當前位置: 首頁>>代碼示例>>Java>>正文


Java OWLDataFactory.getOWLEquivalentClassesAxiom方法代碼示例

本文整理匯總了Java中org.semanticweb.owlapi.model.OWLDataFactory.getOWLEquivalentClassesAxiom方法的典型用法代碼示例。如果您正苦於以下問題:Java OWLDataFactory.getOWLEquivalentClassesAxiom方法的具體用法?Java OWLDataFactory.getOWLEquivalentClassesAxiom怎麽用?Java OWLDataFactory.getOWLEquivalentClassesAxiom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.semanticweb.owlapi.model.OWLDataFactory的用法示例。


在下文中一共展示了OWLDataFactory.getOWLEquivalentClassesAxiom方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addAutoGeneratedClassNames

import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
private void addAutoGeneratedClassNames(OWLOntologyManager manager,
										OWLOntology ontology,
										Map<String, OWLClassExpression> nameMap) {
	
	OWLDataFactory factory = manager.getOWLDataFactory();
	List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
	
	for (Map.Entry<String, OWLClassExpression> entry : nameMap.entrySet()) {
		
		OWLClass subClass = factory.getOWLClass( IRI.create(entry.getKey()) );
		OWLAxiom declAxiom = factory.getOWLEquivalentClassesAxiom( subClass, entry.getValue() );
		
		changes.addAll( manager.addAxiom( ontology, declAxiom ) );
	}
	
	manager.applyChanges( changes );
}
 
開發者ID:klinovp,項目名稱:pronto,代碼行數:18,代碼來源:KBStandaloneLoader.java

示例2: executeDLQuery

import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
/**
 * Execute the DL query on the given ontology graph. Uses the factory to create 
 * the {@link OWLReasoner} for an internal query ontology.
 * 
 * @param dlQuery
 * @param graph
 * @param reasonerFactory
 * @return set of {@link OWLClass} which 
 * @throws OWLParserException
 * @throws OWLOntologyCreationException
 */
public static Set<OWLClass> executeDLQuery(String dlQuery, OWLGraphWrapper graph, 
		OWLReasonerFactory reasonerFactory) throws OWLParserException, OWLOntologyCreationException 
{
	// create parser and parse DL query string
	ManchesterSyntaxTool parser = null;
	
	OWLClassExpression ce;
	try {
		parser = new ManchesterSyntaxTool(graph.getSourceOntology(), graph.getSupportOntologySet());
		ce = parser.parseManchesterExpression(dlQuery);
	} finally {
		// always dispose parser to avoid a memory leak
		if (parser != null) {
			parser.dispose();
		}
	}
	
	// create query ontology
	OWLOntologyManager m = OWLManager.createOWLOntologyManager();
	OWLOntology queryOntology = m.createOntology(IRI.generateDocumentIRI(), graph.getAllOntologies());
	OWLDataFactory f = m.getOWLDataFactory();
	OWLClass qc = f.getOWLClass(IRI.create("http://owltools.org/Q"));
	OWLEquivalentClassesAxiom ax = f.getOWLEquivalentClassesAxiom(ce, qc);
	m.addAxiom(queryOntology, ax);
	
	Set<OWLClass> subset = executeQuery(ce, queryOntology, reasonerFactory);
	if(subset.isEmpty()) {
		LOG.warn("No classes found for query subclass of:"+dlQuery);
	}
	return subset;
}
 
開發者ID:owlcollab,項目名稱:owltools,代碼行數:43,代碼來源:DLQueryTool.java

示例3: translateDisjointsToEquivalents

import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
/**
 * For every pair X DisjointWith Y, generate an axiom
 * A and Y = Nothing
 * 
 * (may become deprecated after Elk supports disjoints)
 * 
 * @param ont
 * @param manager
 * @param dataFactory
 */
public static void translateDisjointsToEquivalents(OWLOntology ont, OWLOntologyManager manager, OWLDataFactory dataFactory) {
	for (OWLDisjointClassesAxiom dca : ont.getAxioms(AxiomType.DISJOINT_CLASSES, Imports.INCLUDED)) {
		for (OWLClassExpression ce1 : dca.getClassExpressions()) {
			for (OWLClassExpression ce2 : dca.getClassExpressions()) {
				if (ce1.compareTo(ce2) <= 0)
					continue;
				OWLEquivalentClassesAxiom eca = dataFactory.getOWLEquivalentClassesAxiom(dataFactory.getOWLNothing(),
						dataFactory.getOWLObjectIntersectionOf(ce1, ce2));
				manager.addAxiom(ont, eca);
				// TODO - remove if requested
			}
		}
	}
}
 
開發者ID:owlcollab,項目名稱:owltools,代碼行數:25,代碼來源:Mooncat.java

示例4: visit

import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
@Override
public OWLAxiom visit(NominalAxiom axiom) {
	Objects.requireNonNull(axiom);
	OWLNamedIndividual owlIndividual = translator.getTranslationRepository()
			.getOWLNamedIndividual(axiom.getIndividual());
	OWLClass owlClass = translator.getTranslationRepository().getOWLClass(axiom.getClassExpression());
	Set<OWLAnnotation> owlAnnotations = translateAnnotations(axiom.getAnnotations());
	OWLDataFactory dataFactory = ontology.getOWLOntologyManager().getOWLDataFactory();
	OWLObjectOneOf owlObjectOneOf = dataFactory.getOWLObjectOneOf(owlIndividual);
	Set<OWLClassExpression> owlClassExpressions = new HashSet<>();
	owlClassExpressions.add(owlObjectOneOf);
	owlClassExpressions.add(owlClass);
	return dataFactory.getOWLEquivalentClassesAxiom(owlClassExpressions, owlAnnotations);
}
 
開發者ID:julianmendez,項目名稱:jcel,代碼行數:15,代碼來源:ReverseAxiomTranslator.java

示例5: getHierarchyNode

import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
protected HierarchyNode<AtomicConcept> getHierarchyNode(
		OWLClassExpression classExpression) {
	checkPreConditions(classExpression);
	classifyClasses();
	if (!isConsistent())
		return m_atomicConceptHierarchy.getBottomNode();
	else if (classExpression instanceof OWLClass) {
		AtomicConcept atomicConcept = H((OWLClass) classExpression);
		HierarchyNode<AtomicConcept> node = m_atomicConceptHierarchy
				.getNodeForElement(atomicConcept);
		if (node == null)
			node = new HierarchyNode<AtomicConcept>(atomicConcept,
					Collections.singleton(atomicConcept),
					Collections.singleton(m_atomicConceptHierarchy
							.getTopNode()),
					Collections.singleton(m_atomicConceptHierarchy
							.getBottomNode()));
		return node;
	} else {
		OWLDataFactory factory = getDataFactory();
		OWLClass queryConcept = factory.getOWLClass(IRI
				.create("internal:query-concept"));
		OWLAxiom classDefinitionAxiom = factory
				.getOWLEquivalentClassesAxiom(queryConcept, classExpression);
		final Tableau tableau = getTableau(classDefinitionAxiom);
		HierarchySearch.Relation<AtomicConcept> hierarchyRelation = new HierarchySearch.Relation<AtomicConcept>() {
			public boolean doesSubsume(AtomicConcept parent,
					AtomicConcept child) {
				Individual freshIndividual = Individual
						.createAnonymous("fresh-individual");
				return !tableau.isSatisfiable(true, Collections
						.singleton(Atom.create(child, freshIndividual)),
						null, null, Collections.singleton(Atom.create(
								parent, freshIndividual)), null,
						ReasoningTaskDescription.isConceptSubsumedBy(child,
								parent));
			}
		};
		HierarchyNode<AtomicConcept> extendedHierarchy = HierarchySearch
				.findPosition(hierarchyRelation,
						AtomicConcept.create("internal:query-concept"),
						m_atomicConceptHierarchy.getTopNode(),
						m_atomicConceptHierarchy.getBottomNode());
		tableau.clearAdditionalDLOntology();
		return extendedHierarchy;
	}
}
 
開發者ID:robertoyus,項目名稱:HermiT-android,代碼行數:48,代碼來源:Reasoner.java

示例6: main

import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
public static void main(String[] args) throws OWLOntologyCreationException {
	OWLOntologyManager man = OWLManager.createOWLOntologyManager();
	OWLDataFactory dataFactory = man.getOWLDataFactory();

	// Load your ontology.
	OWLOntology ont = man.loadOntologyFromOntologyDocument(new File(
			"c:/ontologies/ontology.owl"));

	// Create an ELK reasoner.
	OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
	OWLReasoner reasoner = reasonerFactory.createReasoner(ont);

	// Create your desired query class expression. In this example we
	// will query ObjectIntersectionOf(A ObjectSomeValuesFrom(R B)).
	PrefixManager pm = new DefaultPrefixManager("http://example.org/");
	OWLClass A = dataFactory.getOWLClass(":A", pm);
	OWLObjectProperty R = dataFactory.getOWLObjectProperty(":R", pm);
	OWLClass B = dataFactory.getOWLClass(":B", pm);
	OWLClassExpression query = dataFactory.getOWLObjectIntersectionOf(A,
			dataFactory.getOWLObjectSomeValuesFrom(R, B));

	// Create a fresh name for the query.
	OWLClass newName = dataFactory.getOWLClass(IRI.create("temp001"));
	// Make the query equivalent to the fresh class
	OWLAxiom definition = dataFactory.getOWLEquivalentClassesAxiom(newName,
			query);
	man.addAxiom(ont, definition);

	// Remember to either flush the reasoner after the ontology change
	// or create the reasoner in non-buffering mode. Note that querying
	// a reasoner after an ontology change triggers re-classification of
	// the whole ontology which might be costly. Therefore, if you plan
	// to query for multiple complex class expressions, it will be more
	// efficient to add the corresponding definitions to the ontology at
	// once before asking any queries to the reasoner.
	reasoner.flush();

	// You can now retrieve subclasses, superclasses, and instances of
	// the query class by using its new name instead.
	reasoner.getSubClasses(newName, true);
	reasoner.getSuperClasses(newName, true);
	reasoner.getInstances(newName, false);

	// After you are done with the query, you should remove the definition
	man.removeAxiom(ont, definition);

	// You can now add new definitions for new queries in the same way

	// After you are done with all queries, do not forget to free the
	// resources occupied by the reasoner
	reasoner.dispose();
}
 
開發者ID:liveontologies,項目名稱:elk-reasoner,代碼行數:53,代碼來源:QueryingUnnamedClassExpressions.java

示例7: expand

import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
/**
 * Create the GCIs for BioChEBI. Add the axioms into the given ontology.
 * 
 * @param ontology
 * @param ignoredClasses
 */
public void expand(OWLOntology ontology, Set<OWLClass> ignoredClasses) {
	final OWLOntologyManager manager = ontology.getOWLOntologyManager();
	final OWLDataFactory factory = manager.getOWLDataFactory();
	
	// scan axioms
	Set<OWLSubClassOfAxiom> axioms = ontology.getAxioms(AxiomType.SUBCLASS_OF, Imports.INCLUDED);
	for (OWLSubClassOfAxiom axiom : axioms) {
		OWLClassExpression superCE = axiom.getSuperClass();
		OWLClassExpression subCE = axiom.getSubClass();
		if (subCE.isAnonymous()) {
			// sub class needs to be an named OWLClass
			continue;
		}

		if (superCE instanceof OWLObjectSomeValuesFrom == false) {
			continue;
		}
		OWLObjectSomeValuesFrom some = (OWLObjectSomeValuesFrom) superCE;

		OWLObjectPropertyExpression expression = some.getProperty();
		if (expression.isAnonymous()) {
			// object property expression needs to be a named OWLObjectProperty 
			continue;
		}

		OWLObjectProperty p = (OWLObjectProperty) expression;
		
		Set<OWLObjectProperty> expansions = expansionMap.get(p);
		if (expansions == null) {
			continue;
		}

		// get content for GCI
		OWLClassExpression y = some.getFiller();
		OWLClass x = subCE.asOWLClass();
		if (ignoredClasses.contains(x)) {
			continue;
		}
		for (OWLObjectProperty createProperty : expansions) {
			OWLClassExpression ce1 = factory.getOWLObjectSomeValuesFrom(createProperty, x);
			OWLClassExpression ce2 = factory.getOWLObjectSomeValuesFrom(createProperty, y);
			OWLEquivalentClassesAxiom eq = factory.getOWLEquivalentClassesAxiom(ce1, ce2);
			manager.addAxiom(ontology, eq);
		}
	}
	
	Set<OWLOntology> imports = ontology.getImports();
	StringBuilder sb = new StringBuilder();
	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	sb.append("Generated on ").append(dateFormat.format(new Date())).append(" using the following import chain:");
	for (OWLOntology owlOntology : imports) {
		OWLOntologyID ontologyID = owlOntology.getOntologyID();
		sb.append(" ");
		appendOntologyId(ontologyID, sb);
	}
	addComment(sb.toString(), ontology);
}
 
開發者ID:owlcollab,項目名稱:owltools,代碼行數:64,代碼來源:BioChebiGenerator.java

示例8: generateAxioms

import org.semanticweb.owlapi.model.OWLDataFactory; //導入方法依賴的package包/類
private Map<Bioentity, Set<OWLClass>> generateAxioms(OWLOntology generatedContainer, Map<Bioentity, ? extends Collection<GeneAnnotation>> annMap, Map<Bioentity, Set<OWLClass>> allExistingAnnotations, Map<OWLClass, PredicationDataContainer> sourceData) {
	final OWLGraphWrapper g = getGraph();
	final OWLDataFactory f = g.getDataFactory();
	final OWLOntologyManager m = g.getManager();
	
	Map<Bioentity, Set<OWLClass>> allGeneratedClasses = new HashMap<Bioentity, Set<OWLClass>>();
	for(Entry<Bioentity, ? extends Collection<GeneAnnotation>> entry : annMap.entrySet()) {
		Set<OWLClass> generatedClasses = new HashSet<OWLClass>();
		Set<OWLClass> existingAnnotations = new HashSet<OWLClass>();
		Bioentity e = entry.getKey();
		for (GeneAnnotation ann : entry.getValue()) {
			// skip ND evidence annotations
			String evidenceString = ann.getShortEvidence();
			if ("ND".equals(evidenceString)) {
				continue;
			}
			// parse annotation cls
			String annotatedToClassString = ann.getCls();
			OWLClass annotatedToClass = g.getOWLClassByIdentifierNoAltIds(annotatedToClassString);
			if (annotatedToClass == null) {
				LOG.warn("Skipping annotation for prediction. Could not find cls for id: "+annotatedToClassString);
				continue;
			}
			// add annotation class (and its super classes as known annotation) 
			existingAnnotations.add(annotatedToClass);
			existingAnnotations.addAll(reasoner.getSuperClasses(annotatedToClass, false).getFlattened());
			
			// parse c16 expressions
			List<List<ExtensionExpression>> extensionExpressionGroups = ann.getExtensionExpressions();
			if (extensionExpressionGroups != null && !extensionExpressionGroups.isEmpty()) {
				for (List<ExtensionExpression> group : extensionExpressionGroups) {
					Set<OWLClassExpression> units = new HashSet<OWLClassExpression>();
					for (ExtensionExpression ext : group) {
						String extClsString = ext.getCls();
						String extRelString = ext.getRelation();
						OWLClass extCls = f.getOWLClass(g.getIRIByIdentifier(extClsString));
						OWLObjectProperty extRel = g.getOWLObjectPropertyByIdentifier(extRelString);
						if (extRel == null) {
							continue;
						}
						units.add(f.getOWLObjectSomeValuesFrom(extRel, extCls));
					}
					if (units.isEmpty()) {
						continue;
					}
					units.add(annotatedToClass);
					final OWLClassExpression groupExpression = f.getOWLObjectIntersectionOf(units);
					OWLClass generatedClass = f.getOWLClass(IRI.generateDocumentIRI());
					OWLAxiom axiom = f.getOWLEquivalentClassesAxiom(generatedClass, groupExpression);
					m.addAxiom(generatedContainer, axiom);
					generatedClasses.add(generatedClass);
					sourceData.put(generatedClass, new PredicationDataContainer(ann, annotatedToClass, evidenceString, groupExpression, group));
				}
			}
		}
		if (generatedClasses.isEmpty() == false) {
			allGeneratedClasses.put(e, generatedClasses);
			allExistingAnnotations.put(e, existingAnnotations);
		}
	}
	return allGeneratedClasses;
}
 
開發者ID:owlcollab,項目名稱:owltools,代碼行數:63,代碼來源:FoldBasedPredictor.java


注:本文中的org.semanticweb.owlapi.model.OWLDataFactory.getOWLEquivalentClassesAxiom方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。