<commit_before>package com.ge.research.sadl.jena;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Property;

public class OntModelProvider {
	
	private static OntModel sadlBaseModel;
	private static OntModel sadlListModel;
	
	static class OntModelAdapter extends AdapterImpl  {
		String modelName;
		OntModel model;
		List<Object> otherContent;
		Map<EObject, Property> impliedPropertiesUsed = null;
		boolean isLoading = false;
		boolean hasCircularImport = false;
		
		@Override
		public boolean isAdapterForType(Object type) {
			return OntModel.class == type;
		}
	}
	
	public static void registerResource(Resource resource) {
		OntModelAdapter a = findAdapter(resource);
		if (a == null) {
			a = new OntModelAdapter();
			a.isLoading = true;
			resource.eAdapters().add(a);
		}
	}
	
	public static boolean checkForCircularImport(Resource resource) {
		OntModelAdapter a = findAdapter(resource);
		if (a != null) {
			if (a.isLoading) {
				a.hasCircularImport = true;
				return true;
			}
		}
		return false;
	}
	
	public static boolean hasCircularImport(Resource resource) {
		OntModelAdapter a = findAdapter(resource);
		if (a != null) {
			return a.hasCircularImport;
		}
		return false;
	}

	public static void attach(Resource resource, OntModel model, String modelName) {
		OntModelAdapter adapter = findAdapter(resource);
		if (adapter == null) {
			adapter = new OntModelAdapter();
			resource.eAdapters().add(adapter);
		}
		adapter.modelName = modelName;
		adapter.model = model;
		adapter.isLoading = false;  // loading is complete
	}
	
	public static void addOtherContent(Resource resource, Object otherContent) {
		OntModelAdapter adapter = findAdapter(resource);
		if (adapter != null) {
			if (adapter.otherContent == null) {
				adapter.otherContent = new ArrayList<Object>();
			}
			adapter.otherContent.add(otherContent);
		}
	}
	
	public static List<Object> getOtherContent(Resource resource) {
		OntModelAdapter a = findAdapter(resource);
		if (a != null) {
			return a.otherContent;
		}
		return null;
	}
	
	public static void addImpliedProperties(Resource resource, Map<EObject, Property> impliedProperties) {
		if (resource != null) {
			OntModelAdapter a = findAdapter(resource);
			if (a == null) {
				a = new OntModelAdapter();
				a.isLoading = true;
				resource.eAdapters().add(a);
			}
			a.impliedPropertiesUsed = impliedProperties;
		}
	}
	
	public static Property getImpliedProperty(Resource resource, EObject context) {
		OntModelAdapter a = findAdapter(resource);
		if (a != null && a.impliedPropertiesUsed != null) {
			return a.impliedPropertiesUsed.get(context);
		}
		return null;
	}
	
	public static OntModelAdapter findAdapter(Resource resource) {
		if (resource != null) {
			for (Adapter a : resource.eAdapters()) {
				if (a instanceof OntModelAdapter) {
					return ((OntModelAdapter) a);
				}
			}
		}
		return null;
	}
	
	public static OntModel find(Resource resource) {
		OntModelAdapter a = findAdapter(resource);
		if (a != null) {
			return a.model;
		}
		return null;
	}
	
	public static String getModelName(Resource resource) {
		OntModelAdapter a = findAdapter(resource);
		if (a != null) {
			return a.modelName;
		}
		return null;
	}

	public static OntModel getSadlBaseModel() {
		return sadlBaseModel;
	}

	public static void setSadlBaseModel(OntModel model) {
		sadlBaseModel = model;
	}

	public static OntModel getSadlListModel() {
		return sadlListModel;
	}

	public static void setSadlListModel(OntModel model) {
		sadlListModel = model;
	}
	
}
<commit_msg>don't create an adapter for implied properties if empty<commit_after>package com.ge.research.sadl.jena;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Property;

public class OntModelProvider {
	
	private static OntModel sadlBaseModel;
	private static OntModel sadlListModel;
	
	static class OntModelAdapter extends AdapterImpl  {
		String modelName;
		OntModel model;
		List<Object> otherContent;
		Map<EObject, Property> impliedPropertiesUsed = null;
		boolean isLoading = false;
		boolean hasCircularImport = false;
		
		@Override
		public boolean isAdapterForType(Object type) {
			return OntModel.class == type;
		}
	}
	
	public static void registerResource(Resource resource) {
		OntModelAdapter a = findAdapter(resource);
		if (a == null) {
			a = new OntModelAdapter();
			a.isLoading = true;
			resource.eAdapters().add(a);
		}
	}
	
	public static boolean checkForCircularImport(Resource resource) {
		OntModelAdapter a = findAdapter(resource);
		if (a != null) {
			if (a.isLoading) {
				a.hasCircularImport = true;
				return true;
			}
		}
		return false;
	}
	
	public static boolean hasCircularImport(Resource resource) {
		OntModelAdapter a = findAdapter(resource);
		if (a != null) {
			return a.hasCircularImport;
		}
		return false;
	}

	public static void attach(Resource resource, OntModel model, String modelName) {
		OntModelAdapter adapter = findAdapter(resource);
		if (adapter == null) {
			adapter = new OntModelAdapter();
			resource.eAdapters().add(adapter);
		}
		adapter.modelName = modelName;
		adapter.model = model;
		adapter.isLoading = false;  // loading is complete
	}
	
	public static void addOtherContent(Resource resource, Object otherContent) {
		OntModelAdapter adapter = findAdapter(resource);
		if (adapter != null) {
			if (adapter.otherContent == null) {
				adapter.otherContent = new ArrayList<Object>();
			}
			adapter.otherContent.add(otherContent);
		}
	}
	
	public static List<Object> getOtherContent(Resource resource) {
		OntModelAdapter a = findAdapter(resource);
		if (a != null) {
			return a.otherContent;
		}
		return null;
	}
	
	public static void addImpliedProperties(Resource resource, Map<EObject, Property> impliedProperties) {
		if (resource != null && impliedProperties != null) {
			OntModelAdapter a = findAdapter(resource);
			if (a == null) {
				a = new OntModelAdapter();
				a.isLoading = true;
				resource.eAdapters().add(a);
			}
			a.impliedPropertiesUsed = impliedProperties;
		}
	}
	
	public static Property getImpliedProperty(Resource resource, EObject context) {
		OntModelAdapter a = findAdapter(resource);
		if (a != null && a.impliedPropertiesUsed != null) {
			return a.impliedPropertiesUsed.get(context);
		}
		return null;
	}
	
	public static OntModelAdapter findAdapter(Resource resource) {
		if (resource != null) {
			for (Adapter a : resource.eAdapters()) {
				if (a instanceof OntModelAdapter) {
					return ((OntModelAdapter) a);
				}
			}
		}
		return null;
	}
	
	public static OntModel find(Resource resource) {
		OntModelAdapter a = findAdapter(resource);
		if (a != null) {
			return a.model;
		}
		return null;
	}
	
	public static String getModelName(Resource resource) {
		OntModelAdapter a = findAdapter(resource);
		if (a != null) {
			return a.modelName;
		}
		return null;
	}

	public static OntModel getSadlBaseModel() {
		return sadlBaseModel;
	}

	public static void setSadlBaseModel(OntModel model) {
		sadlBaseModel = model;
	}

	public static OntModel getSadlListModel() {
		return sadlListModel;
	}

	public static void setSadlListModel(OntModel model) {
		sadlListModel = model;
	}
	
}

{'fraction_non_alphanumeric': 0.10286677908937605, 'fraction_numerical': 0.0, 'mean_word_length': 4.016265452179571, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2283280', 'n_tokens_mistral': 2754, 'n_tokens_neox': 2416, 'n_words': 600}