org.semanticweb.owlapi.model.AddAxiom Java Examples

The following examples show how to use org.semanticweb.owlapi.model.AddAxiom. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TableToAxiomConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void parse(File myFile) throws IOException {
	try (BufferedReader reader = new BufferedReader(new FileReader(myFile))) {
		for(String line : IOUtils.readLines(reader)) {
			String[] row = line.split("\t");
			if (config.defaultCol1 != null)
				row[0] = config.defaultCol1;
			if (config.defaultCol2 != null) {
				String[] row2 = new String[2];
				row2[0] = row[0];
				row = row2;
				row[1] = config.defaultCol2;
			}
			addRow(row);
		}
	}

	if (config.individualsType != null) {
		OWLDataFactory df = graph.getDataFactory();
		graph.getManager().applyChange(new AddAxiom(graph.getSourceOntology(), 
				df.getOWLDeclarationAxiom(config.individualsType)));
	}

}
 
Example #2
Source File: OwlChangesLoaderFactory.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
Set<OWLAxiom> getPendingAxiomAdditions() {
	Set<OWLAxiom> added = new HashSet<OWLAxiom>();
	for (OWLOntologyChange change : pendingChanges_) {
		if (change instanceof AddAxiom) {
			added.add(change.getAxiom());
		}
	}
	return added;
}
 
Example #3
Source File: OWLView.java    From relex with Apache License 2.0 5 votes vote down vote up
/**
* Print out RelEx relations. All relations shown
* in a binary form.
*
* Example:
*       _subj(throw, John)
*       _obj(throw, ball)
*       tense(throw, past)
*       definite-FLAG(ball, T)
*       noun_number(ball, singular)
*/
public void printRelations(ParsedSentence parse, String sentence, int sentence_id, String ontologyname)
{
	try
	{
		sent = sentence;

		//Add the sentence to Sentence Class
		this.sentence_id = sentence_id;
		sentenceInd = factory.getOWLNamedIndividual(IRI.create(ontologyURI + "#" + "sentence_" + sentence_id));
		//OWLAnnotationProperty p = new OWLAnnotationPropertyImpl(IRI.create(sentence));

		//OWLAnnotation label = factory.getOWLAnnotation(sentence);
		OWLOntologyFormat ontologyFormat = manager.getOntologyFormat(ontology);
		OWLAnnotation label = (OWLAnnotation) factory.getOWLAnnotationProperty(sentence, (PrefixManager) ontologyFormat);

		OWLClassAssertionAxiom sentClass = factory.getOWLClassAssertionAxiom(this.sentence,sentenceInd);
		OWLAnnotationAssertionAxiom labelClass = factory.getOWLAnnotationAssertionAxiom((OWLAnnotationSubject) sentClass, label);
		manager.applyChange(new AddAxiom(ontology, sentClass));
		manager.applyChange(new AddAxiom(ontology, labelClass));

		printRelations(parse, null);

	}
	catch (OWLOntologyChangeException ex)
	{
		Logger.getLogger(OWLView.class.getName()).log(Level.SEVERE, null, ex);
	}
}
 
Example #4
Source File: OboOntologyReleaseRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addAxiom(String info, OWLAxiom ax, OWLOntology ont, OWLOntologyManager manager, OWLDataFactory factory, List<String> reasonerReportLines) {
	if (oortConfig.isUseIsInferred()) {
		ax = AxiomAnnotationTools.markAsInferredAxiom(ax, factory);
	}
	manager.applyChange(new AddAxiom(ont, ax));
	String ppax = owlpp.render(ax);
	String rptLine = info+"\t"+ppax;
	reasonerReportLines.add(rptLine);
}
 
Example #5
Source File: OWLGraphWrapperEdgeTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testEdgeCache() throws Exception {
	OWLGraphWrapper g = getGraph("graph/cache-test.obo");
	
	OWLOntology o = g.getSourceOntology();
	OWLOntologyManager m = o.getOWLOntologyManager();
	OWLDataFactory f = m.getOWLDataFactory();
	
	OWLClass orphan = g.getOWLClassByIdentifier("FOO:0004");
	OWLClass root = g.getOWLClassByIdentifier("FOO:0001");
	
	g.getEdgesBetween(orphan, root); //just to trigger the cache
	
	OWLSubClassOfAxiom ax = f.getOWLSubClassOfAxiom(orphan, root);
	AddAxiom addAx = new AddAxiom(o, ax);
	m.applyChange(addAx);
	
	Set<OWLGraphEdge> edges = g.getEdgesBetween(orphan, root);
	assertNotNull(edges);
	
	assertEquals(0, edges.size());
	
	g.clearCachedEdges(); // test clear cache method
	
	edges = g.getEdgesBetween(orphan, root);
	assertNotNull(edges);
	
	assertEquals(1, edges.size());
}
 
Example #6
Source File: OWLGraphWrapperBasic.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void mergeOntology(OWLOntology extOnt, LabelPolicy labelPolicy) throws OWLOntologyCreationException {
	OWLOntologyManager manager = getManager();
	LOG.info("Merging "+extOnt+" policy: "+labelPolicy);
	for (OWLAxiom axiom : extOnt.getAxioms()) {
		if (labelPolicy != LabelPolicy.ALLOW_DUPLICATES) {
			if (axiom instanceof OWLAnnotationAssertionAxiom) {
				OWLAnnotationAssertionAxiom aa = (OWLAnnotationAssertionAxiom)axiom;
				if (aa.getProperty().isLabel()) {
					OWLAnnotationSubject subj = aa.getSubject();
					if (subj instanceof IRI) {
						Optional<OWLLiteral> label = null;
						for (OWLAnnotationAssertionAxiom a1 : sourceOntology.getAnnotationAssertionAxioms(subj)) {
							if (a1.getProperty().isLabel()) {
								label = a1.getValue().asLiteral();
							}
						}
						if (label != null && label.isPresent()) {
							if (labelPolicy == LabelPolicy.PRESERVE_SOURCE) {
								LOG.info("Preserving existing label:" +subj+" "+label+" // ditching: "+axiom);
								continue;
							}
							if (labelPolicy == LabelPolicy.PRESERVE_EXT) {
								LOG.info("Replacing:" +subj+" "+label+" with: "+axiom);
								LOG.error("NOT IMPLEMENTED");
							}
						}
					}
				}
			}
		}
		manager.applyChange(new AddAxiom(sourceOntology, axiom));
	}
	for (OWLImportsDeclaration oid: extOnt.getImportsDeclarations()) {
		manager.applyChange(new AddImport(sourceOntology, oid));
	}
	addCommentToOntology(sourceOntology, "Includes "+summarizeOntology(extOnt));
}
 
Example #7
Source File: TemplatedTransformer.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Set<OWLOntologyChange> tr(OWLAxiom inAxiom, Mapping m) {
	Set<OWLOntologyChange> chgs = new HashSet<OWLOntologyChange>();
	boolean isModified = false;
	OWLAxiom newAxiom = null;
	if (inAxiom instanceof OWLEquivalentClassesAxiom) {
		OWLEquivalentClassesAxiom aa = (OWLEquivalentClassesAxiom)inAxiom;
		Set<OWLClassExpression> xs = new HashSet<OWLClassExpression>();
		for (OWLClassExpression x : aa.getClassExpressions()) {
			OWLClassExpression x2 = replace(x, m);
			if (x2 == null) {
				xs.add(x);
			}
			else {
				isModified = true;
				xs.add(x2);
				LOG.info("  TR : "+x+ " ---> "+x2);
			}
		}
		if (isModified) {
			newAxiom = getOWLDataFactory().getOWLEquivalentClassesAxiom(xs);
		}
	}
	if (isModified) {
		if (m.isReplace) {
			chgs.add(new RemoveAxiom(ontology, inAxiom));
		}
		chgs.add(new AddAxiom(ontology, newAxiom));
	}
	return chgs;
	
}
 
Example #8
Source File: Similarity.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * translates similarity results into OWL Axioms and saves axioms into an OWL Ontology
 *
 * @param ont
 */
public void addResultsToOWLOntology(OWLOntology ont) {
	if (!isComparable)
		return;
	OWLGraphWrapper graph = simEngine.getGraph();
	for (OWLAxiom axiom: translateResultsToOWLAxioms()) {
		AddAxiom aa = new AddAxiom(ont, axiom);
		graph.getManager().applyChange(aa);
	}
}
 
Example #9
Source File: OWLGraphManipulator.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Relaxes all {@code OWLObjectIntersectionOf}s. This method will relax 
 * {@code OWLSubClassOfAxiom}s, whose superclass is an {@code OWLObjectIntersectionOf}, 
 * into multiple {@code OWLSubClassOfAxiom}s, using a <a 
 * href='http://owlapi.sourceforge.net/javadoc/org/semanticweb/owlapi/SplitSubClassAxioms.html'>
 * SplitSubClassAxioms</a>. It will also relax {@code OWLSubClassOfAxiom}s, whose 
 * superclass is an {@code OWLObjectSomeValuesFrom} with a filler being an 
 * {@code OWLObjectIntersectionOf}, into multiple {@code OWLSubClassOfAxiom}s with 
 * an {@code OWLObjectSomeValuesFrom} as superclass, with the same 
 * {@code OWLPropertyExpression}, and individual operands as filler. 
 * <p>
 * Note that it is likely that the {@code OWLObjectIntersectionOf}s where used in
 * {@code OWLEquivalentClassesAxiom}s, rather than in {@code OWLSubClassOfAxiom}s. 
 * But the method {@link #convertEquivalentClassesToSuperClasses()} would have transformed 
 * them into {@code OWLSubClassOfAxiom}s. It must be called before this method.
 * 
 * @see #performDefaultModifications()
 * @see #convertEquivalentClassesToSuperClasses()
 */
private void splitSubClassAxioms() {
    log.info("Relaxing OWLSubClassOfAxioms whose superclass is an OWLObjectIntersectionOf");
    
    //first, split subClassOf axioms whose superclass is an OWLObjectIntersectionOf
    SplitSubClassAxioms split = new SplitSubClassAxioms(
            this.getOwlGraphWrapper().getAllOntologies(), 
            this.getOwlGraphWrapper().getDataFactory());
    this.getOwlGraphWrapper().getManager().applyChanges(split.getChanges());
    this.triggerWrapperUpdate();
    
    //some ontologies use an OWLObjectIntersectionOf as the filler of 
    //an OWLObjectSomeValuesFrom class expression. We go only one level down 
    //(i.e., we would not translate another OWLObjectSomeValuesFrom part of the 
    //OWLObjectIntersectionOf)
    OWLDataFactory dataFactory = this.getOwlGraphWrapper().getDataFactory();
    List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
    for (OWLOntology ont : this.getOwlGraphWrapper().getAllOntologies()) {
        for (OWLSubClassOfAxiom ax : ont.getAxioms(AxiomType.SUBCLASS_OF)) {
            OWLClassExpression superClsExpr = ax.getSuperClass();
            if (superClsExpr instanceof OWLObjectSomeValuesFrom) {
                OWLObjectSomeValuesFrom someValuesFrom = 
                        (OWLObjectSomeValuesFrom) superClsExpr;
                if (someValuesFrom.getFiller() instanceof OWLObjectIntersectionOf) {
                    //remove original axiom
                    changes.add(new RemoveAxiom(ont, ax));
                    
                    OWLObjectIntersectionOf filler = 
                            (OWLObjectIntersectionOf) someValuesFrom.getFiller();
                    for (OWLClassExpression op : filler.getOperands()) {
                        //we accept only OWLClasses, otherwise we would need to compose 
                        //OWLObjectPropertyExpressions
                        if (op instanceof OWLClass) {
                            OWLAxiom replAx = dataFactory.
                                    getOWLSubClassOfAxiom(ax.getSubClass(), 
                                    dataFactory.getOWLObjectSomeValuesFrom(
                                                someValuesFrom.getProperty(), op));
                            changes.add(new AddAxiom(ont, replAx));
                        }
                    }
                }
                
            }
        }
    }
    this.getOwlGraphWrapper().getManager().applyChanges(changes);
    this.triggerWrapperUpdate();
    
    log.info("OWLObjectIntersectionOf relaxation done.");
}
 
Example #10
Source File: DescriptionTreeSimilarity.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * makes a reduced union expression.
 * 
 * Uses the following two reduction rules:
 * 
 * (r1 some X) U (r2 some Y) ==> lcs(r1,r2) some MakeUnionOf(X,Y)
 * (r1 some X) U X ==> reflexive-version-of-r1 some X
 * 
 * TODO: test for (r some r some X) u (r some X) cases. needs to be done over final expression.
 *  
 * if a reduced form cannot be made, returns null
 * 
 * @param xa
 * @param xb
 * @return class expression
 */
private OWLClassExpression makeUnionUsingReflexiveProperty(OWLClassExpression xa, OWLClassExpression xb) {
	LOG.info("testing if there is a more compact union expression for "+xa+" ++ "+xb);
	OWLDataFactory df = graph.getDataFactory();
	if (xa instanceof OWLQuantifiedRestriction) {
		// TODO - check before casting
		OWLObjectProperty prop = (OWLObjectProperty) ((OWLQuantifiedRestriction) xa).getProperty();
		OWLClassExpression xaRest = (OWLClassExpression) ((OWLQuantifiedRestriction)xa).getFiller();
		if (xb instanceof OWLQuantifiedRestriction) {
			OWLObjectPropertyExpression p2 =
				propertySubsumer(prop, 
					((OWLQuantifiedObjectRestriction) xb).getProperty());
			
			if (p2 != null) {
				OWLClassExpression xbRest = (OWLClassExpression) ((OWLQuantifiedRestriction)xb).getFiller();
				OWLClassExpression x = makeUnionWithReduction(xaRest,xbRest);
				// todo - mixing some and all
				if (xa instanceof OWLObjectSomeValuesFrom)
					return df.getOWLObjectSomeValuesFrom(p2,x);
				else if (xa instanceof OWLObjectAllValuesFrom)
					return df.getOWLObjectAllValuesFrom(p2, x);
			}
		}
		LOG.info("  test: "+xaRest+" == "+xb);
		

		if (xaRest.equals(xb)) {
			LOG.info("     TRUE: "+xaRest+" == "+xb);

			OWLObjectProperty rprop = null;
			if (graph.getIsReflexive(prop)) {
				rprop = prop;
			}
			if (forceReflexivePropertyCreation) {
				OWLOntologyManager manager = graph.getManager();
				OWLOntology ont = graph.getSourceOntology();
				rprop = 
					df.getOWLObjectProperty(IRI.create(prop.getIRI().toString()+"_reflexive"));
				manager.applyChange(new AddAxiom(ont, df.getOWLSubObjectPropertyOfAxiom(prop, rprop)));
				manager.applyChange(new AddAxiom(ont, df.getOWLTransitiveObjectPropertyAxiom(rprop)));
				LOG.info("  reflexive prop:"+rprop);

			}
			if (rprop != null) {
				if (xa instanceof OWLObjectSomeValuesFrom)
					return df.getOWLObjectSomeValuesFrom(rprop,xb);
				else if (xa instanceof OWLObjectAllValuesFrom)
					return df.getOWLObjectAllValuesFrom(rprop, xb);
			}

		}
	}
	return null;
}
 
Example #11
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@Test
public void proofListener() throws Exception {
	OWLOntologyManager owlManager = OWLManager
			.createConcurrentOWLOntologyManager();
	OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
	OWLClass c = factory.getOWLClass(IRI.create("http://example.org/C"));
	OWLObjectProperty r = factory
			.getOWLObjectProperty(IRI.create("http://example.org/R"));
	OWLObjectProperty s = factory
			.getOWLObjectProperty(IRI.create("http://example.org/S"));
	OWLAxiom ax1 = factory.getOWLSubClassOfAxiom(a, c);
	OWLAxiom ax2 = factory.getOWLSubClassOfAxiom(c, b);
	OWLAxiom ax3 = factory.getOWLSubClassOfAxiom(a,
			factory.getOWLObjectSomeValuesFrom(r, c));
	OWLAxiom ax4 = factory.getOWLSubClassOfAxiom(
			factory.getOWLObjectSomeValuesFrom(s, c), b);
	OWLAxiom ax5 = factory.getOWLSubObjectPropertyOfAxiom(r, s);

	boolean changed = false; // means entailment has changed

	for (boolean bufferringMode : Arrays.asList(true, false)) {
		// creating an ontology
		final OWLOntology ontology = owlManager.createOntology();

		final OWLProver prover = OWLAPITestUtils.createProver(
				OWLAPITestUtils.createReasoner(ontology, bufferringMode));
		OWLSubClassOfAxiom entailment = factory.getOWLSubClassOfAxiom(a, b);
		DynamicProof<? extends Inference<OWLAxiom>> proof = prover
				.getProof(entailment);
		ProofChangeTracker tracker = new ProofChangeTracker();
		proof.addListener(tracker);

		assertFalse(Proofs.isDerivable(proof, entailment));

		// add ax1 and ax2 => ENTAIL
		owlManager.applyChanges(Arrays.asList(new AddAxiom(ontology, ax1),
				new AddAxiom(ontology, ax2)));

		// derivable only in non-buffering mode
		changed = tracker.changed();
		assertEquals(!bufferringMode, changed);
		assertEquals(!bufferringMode,
				Proofs.isDerivable(proof, entailment));
		// but always derivable after flush
		prover.flush();
		changed |= tracker.changed();
		assertTrue(changed);
		assertTrue(Proofs.isDerivable(proof, entailment));

		// remove ax1, add ax3, ax4 => NOT ENTAIL
		owlManager.applyChanges(Arrays.asList(
				new RemoveAxiom(ontology, ax1), new AddAxiom(ontology, ax3),
				new AddAxiom(ontology, ax4)));

		// still derivable only in bufferring mode
		changed = tracker.changed();
		assertEquals(!bufferringMode, changed);
		assertEquals(bufferringMode, Proofs.isDerivable(proof, entailment));
		// always non derivable after flush
		prover.flush();
		changed |= tracker.changed();
		assertTrue(changed);
		assertFalse(Proofs.isDerivable(proof, entailment));

		// add ax5 => ENTAIL
		owlManager.applyChanges(Arrays.asList(new AddAxiom(ontology, ax5)));

		// derivable only in non-buffering mode
		changed = tracker.changed();
		assertEquals(!bufferringMode, changed);
		assertEquals(!bufferringMode,
				Proofs.isDerivable(proof, entailment));
		// but always derivable after flush
		prover.flush();
		changed |= tracker.changed();
		assertTrue(changed);
		assertTrue(Proofs.isDerivable(proof, entailment));

	}

}
 
Example #12
Source File: TableToAxiomConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void addRow(OWLOntology ont, String[] row) {
	for (OWLAxiom ax : rowToAxioms(row)) {
		graph.getManager().applyChange(new AddAxiom(ont, ax));
	}
}
 
Example #13
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@Test
public void proofsUnderOntologyUpdate() throws Exception {
	// loading and classifying via the OWL API
	OWLOntology ontology = loadOntology(
			ProofTest.class.getClassLoader().getResourceAsStream(
					"ontologies/PropertyCompositionsWithHierarchy.owl"));
	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	OWLClass sub = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass sup = factory.getOWLClass(IRI.create("http://example.org/G"));

	// printInferences(reasoner, sub, sup);
	// OWLExpression root =
	// reasoner.getDerivedExpression(factory.getOWLSubClassOfAxiom(sub,
	// sup));
	// System.err.println(OWLProofUtils.printProofTree(root));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(sub, sup));

	// now convert C <= R3 some D to C < S3 some D
	OWLClass c = factory.getOWLClass(IRI.create("http://example.org/C"));
	OWLClass d = factory.getOWLClass(IRI.create("http://example.org/D"));
	OWLObjectProperty r3 = factory
			.getOWLObjectProperty(IRI.create("http://example.org/R3"));
	OWLObjectProperty s3 = factory
			.getOWLObjectProperty(IRI.create("http://example.org/S3"));
	OWLAxiom oldAx = factory.getOWLSubClassOfAxiom(c,
			factory.getOWLObjectSomeValuesFrom(r3, d));
	OWLAxiom newAx = factory.getOWLSubClassOfAxiom(c,
			factory.getOWLObjectSomeValuesFrom(s3, d));

	OWLOntologyManager manager = ontology.getOWLOntologyManager();

	manager.applyChanges(Arrays.asList(new RemoveAxiom(ontology, oldAx),
			new AddAxiom(ontology, newAx)));

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	// printInferences(reasoner, sub, sup);
	// root =
	// reasoner.getDerivedExpression(factory.getOWLSubClassOfAxiom(sub,
	// sup));
	// System.err.println(OWLProofUtils.printProofTree(root));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(sub, sup));
}
 
Example #14
Source File: ProofTestUtils.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
public static <I extends Inference<?>> void proofCompletenessTest(
		final OWLProver prover, final OWLAxiom entailment,
		final Object conclusion, final Proof<? extends I> proof,
		final InferenceJustifier<? super I, ? extends Set<? extends OWLAxiom>> justifier,
		final boolean mustNotBeATautology) {

	final OWLOntology ontology = prover.getRootOntology();
	final OWLOntologyManager manager = ontology.getOWLOntologyManager();

	// compute repairs

	final Set<Set<? extends OWLAxiom>> repairs = new HashSet<Set<? extends OWLAxiom>>();
	MinimalSubsetEnumerators.enumerateRepairs(conclusion, proof, justifier,
			InterruptMonitor.DUMMY,
			new MinimalSubsetCollector<OWLAxiom>(repairs));

	if (mustNotBeATautology) {
		assertFalse("Entailment is a tautology; there are no repairs!",
				repairs.isEmpty());
	}

	for (final Set<? extends OWLAxiom> repair : repairs) {

		final List<OWLOntologyChange> deletions = new ArrayList<OWLOntologyChange>();
		final List<OWLOntologyChange> additions = new ArrayList<OWLOntologyChange>();
		for (final OWLAxiom axiom : repair) {
			deletions.add(new RemoveAxiom(ontology, axiom));
			additions.add(new AddAxiom(ontology, axiom));
		}

		manager.applyChanges(deletions);

		final boolean conclusionDerived = prover.isEntailed(entailment);

		manager.applyChanges(additions);

		assertFalse("Not all proofs were found!\n" + "Conclusion: "
				+ conclusion + "\n" + "Repair: " + repair,
				conclusionDerived);
	}

}
 
Example #15
Source File: ReasonerUtil.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
AddAxiom getCompleteEquivalence(OWLClass ce) {
  Set<OWLClass> equivalentClasses = reasoner.getEquivalentClasses(ce).getEntities();
  OWLEquivalentClassesAxiom equivalentAxiom = factory.getOWLEquivalentClassesAxiom(equivalentClasses);
  return new AddAxiom(ont, equivalentAxiom);
}
 
Example #16
Source File: OWLView.java    From relex with Apache License 2.0 4 votes vote down vote up
public Boolean BinaryRelationCB(String relName,
										FeatureNode srcNode,
										FeatureNode tgtNode)
{
	String srcName = srcNode.get("name").getValue();
	FeatureNode tgt = tgtNode.get("name");
	if (tgt == null)
	{
		System.out.println("Error: No target! rel=" + relName + " and src=" + srcName);
		return false;
	}
	String tgtName = tgt.getValue();
	if (id_map != null)
	{
		srcName = id_map.get(srcNode);
		tgtName = id_map.get(tgtNode);
	}
	//Optimize using StringBuilder
	//Get the Individual type (noun, etc.) and the type_property
	System.out.println("\n\tRELATION (binary) = " + relName + "(" + srcName + ", " + tgtName + ")\n");

	//Cleaning
	if (relName.charAt(0)=='_')
		relName = relName.replaceFirst("_", "");
	if (relName.length()>1)
		if (relName.charAt(1)=='%')
			relName = relName.replaceFirst("%", "");

	if (tgtName.contains("[") || tgtName.contains("]") || srcName.contains("[") || srcName.contains("]") ||
		tgtName.equals("WORD") || srcName.equals("WORD")  || tgtName.contains("misc-") || srcName.contains("misc-")) return false;

	if (srcName.length()>0 && tgtName.length()>0)
	{
		//1º Add the first term to Word Class
		srcName=srcName.replaceAll("[\\%\\s]", "");
		//System.out.println("srcName = " + srcName);
		OWLIndividual src_word = factory.getOWLNamedIndividual(IRI.create(ontologyURI + "#" + srcName));
		OWLClassAssertionAxiom addSrcWord = factory.getOWLClassAssertionAxiom(word,src_word);
		manager.applyChange(new AddAxiom(ontology, addSrcWord));

		//2º Create the property
		relName = relName.replaceAll("[\\%\\ss]", "");
		OWLObjectProperty rel = factory.getOWLObjectProperty(IRI.create(ontologyURI + "#" + relName));

		//3º Add the second term to Word Class
		tgtName = tgtName.replaceAll("[\\%\\s]", "");
		OWLIndividual dst_word = factory.getOWLNamedIndividual(IRI.create(ontologyURI + "#" + tgtName));
		OWLClassAssertionAxiom addDstWord = factory.getOWLClassAssertionAxiom(word,dst_word );
		manager.applyChange(new AddAxiom(ontology, addDstWord));

		//4º Create axiom for the relation
		OWLObjectPropertyAssertionAxiom addrel = factory.getOWLObjectPropertyAssertionAxiom(rel,src_word, dst_word);
		manager.applyChange(new AddAxiom(ontology, addrel));

		//5º Add the words (Class) to the sentence (Class)
		OWLObjectPropertyAssertionAxiom addw1 = factory.getOWLObjectPropertyAssertionAxiom(has,sentenceInd, src_word);
		//OWLObjectPropertyAssertionAxiom addw2 = factory.getOWLObjectPropertyAssertionAxiom(sentenceInd, has,
		//dst_word);


		manager.applyChange(new AddAxiom(ontology, addw1));
		//manager.applyChange(new AddAxiom(ontology, addw2));
	}

	return false;
}
 
Example #17
Source File: OntologyLoader.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void addClass(OWLClass cls, OWLClass parentClass) {
  if (parentClass == null) parentClass = factory.getOWLThing();
  manager.applyChange(new AddAxiom(ontology, factory.getOWLSubClassOfAxiom(cls, parentClass)));
}
 
Example #18
Source File: OwlOntologyChangeProcessorVisitor.java    From elk-reasoner with Apache License 2.0 3 votes vote down vote up
@Override
public void visit(AddAxiom arg) {
	ElkAxiom elkAxiom = OWL_CONVERTER_.convert(arg.getAxiom());

	axiomInserter_.visit(elkAxiom);

	if (LOGGER_.isTraceEnabled())
		LOGGER_.trace("adding " + arg.getAxiom());

}