org.semanticweb.owlapi.model.IRI Java Examples
The following examples show how to use
org.semanticweb.owlapi.model.IRI.
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: OWLGraphWrapperExtended.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Find all corresponding {@link OWLObject}s with an OBO-style alternate identifier. * <p> * WARNING: This methods scans all object annotations in all ontologies. * This is an expensive method. * * @return map of altId to OWLObject (never null) */ public Map<String, OWLObject> getAllOWLObjectsByAltId() { final Map<String, OWLObject> results = new HashMap<String, OWLObject>(); final OWLAnnotationProperty altIdProperty = getAnnotationProperty(OboFormatTag.TAG_ALT_ID.getTag()); if (altIdProperty == null) { return Collections.emptyMap(); } for (OWLOntology o : getAllOntologies()) { Set<OWLAnnotationAssertionAxiom> aas = o.getAxioms(AxiomType.ANNOTATION_ASSERTION); for (OWLAnnotationAssertionAxiom aa : aas) { OWLAnnotationValue v = aa.getValue(); OWLAnnotationProperty property = aa.getProperty(); if (altIdProperty.equals(property) && v instanceof OWLLiteral) { String altId = ((OWLLiteral)v).getLiteral(); OWLAnnotationSubject subject = aa.getSubject(); if (subject instanceof IRI) { OWLObject obj = getOWLObject((IRI) subject); if (obj != null) { results.put(altId, obj); } } } } } return results; }
Example #2
Source File: AssertInferenceTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static List<OWLOntologyChange> handleSupportOntologies(OWLGraphWrapper graph) { OWLOntology ontology = graph.getSourceOntology(); OWLOntologyManager manager = ontology.getOWLOntologyManager(); OWLDataFactory factory = manager.getOWLDataFactory(); List<OWLOntologyChange> removeImportChanges = new ArrayList<OWLOntologyChange>(); Set<OWLOntology> supportOntologySet = graph.getSupportOntologySet(); for (OWLOntology support : supportOntologySet) { Optional<IRI> supportIRI = support.getOntologyID().getOntologyIRI(); if(supportIRI.isPresent()) { IRI ontologyIRI = supportIRI.get(); OWLImportsDeclaration importDeclaration = factory.getOWLImportsDeclaration(ontologyIRI); ChangeApplied status = manager.applyChange(new AddImport(ontology, importDeclaration)); if (ChangeApplied.SUCCESSFULLY == status) { // the change was successful, create remove import for later removeImportChanges.add(new RemoveImport(ontology, importDeclaration)); } } } return removeImportChanges; }
Example #3
Source File: MarkdownRenderer.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void renderAnnotationAxioms(String tag, IRI piri, Set<OWLAnnotationAssertionAxiom> annotationAxioms) { List<String> vs = new ArrayList<String>(); Set<OWLAnnotationAssertionAxiom> consumed = new HashSet<OWLAnnotationAssertionAxiom>(); for (OWLAnnotationAssertionAxiom aaa : annotationAxioms) { if (aaa.getProperty().getIRI().equals(piri)) { StringBuffer v = new StringBuffer(generateText(aaa.getValue())); if (aaa.getAnnotations().size() > 0) { List<String> avs = new ArrayList<String>(); for (OWLAnnotation ann : aaa.getAnnotations()) { avs.add(generateText(ann)); } Collections.sort(avs); v.append(" [ "+StringUtils.join(avs, ", ")+" ]"); } vs.add(v.toString()); consumed.add(aaa); } } annotationAxioms.removeAll(consumed); renderTagValues(tag, vs); }
Example #4
Source File: CommandRunnerBase.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public OWLObjectProperty resolveObjectProperty(String id) { IRI i = null; i = g.getIRIByLabel(id); if (i == null && id.startsWith("http:")) { i = IRI.create(id); } if (i != null) { return g.getDataFactory().getOWLObjectProperty(i); } OWLObjectProperty prop = g.getOWLObjectPropertyByIdentifier(id); if (prop == null && IdTools.isIRIStyleIdSuffix(id)) { id = IdTools.convertToOboStyleId(id); prop = g.getOWLObjectPropertyByIdentifier(id); } if (prop == null) { LOG.warn("Could not find an OWLObjectProperty for id: '"+id+"'"); } return prop; }
Example #5
Source File: ProofTest.java From elk-reasoner with Apache License 2.0 | 6 votes |
@Test public void compositionReflexivity() throws Exception { // loading and classifying via the OWL API final OWLOntology ontology = loadOntology(ProofTest.class .getClassLoader() .getResourceAsStream(ElkTestUtils.TEST_INPUT_LOCATION + "/classification/CompositionReflexivity.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/B")); // printInferences(reasoner, sub, sup); ProofTestUtils.provabilityTest(prover, factory.getOWLSubClassOfAxiom(sub, sup)); }
Example #6
Source File: AltIdInSignatureTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void test() throws Exception { ParserWrapper parser = new ParserWrapper(); IRI iri = IRI.create(getResource("verification/altid_in_signature.obo").getAbsoluteFile()); OWLGraphWrapper graph = parser.parseToOWLGraph(iri.toString()); AltIdInSignature check = new AltIdInSignature(); Collection<CheckWarning> warnings = check.check(graph, graph.getAllOWLObjects()); assertEquals(2, warnings.size()); final IRI offendingIRI = IRI.create("http://purl.obolibrary.org/obo/FOO_0003"); for (CheckWarning warning : warnings) { assertTrue(warning.getIris().contains(offendingIRI)); assertFalse(warning.isFatal()); } }
Example #7
Source File: LocalMirrorIRIMapper.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Parse the inputStream as a partial redirect mapping file and extract IRI mappings. * * Optional: Resolve relative file paths with the given parent folder. * * @param inputStream input stream (never null) * @param parentFolder folder or null * @return mappings * @throws IOException * @throws IllegalArgumentException if input stream is null */ static Map<IRI, IRI> parseDirectoryMappingFile(InputStream inputStream, final File parentFolder) throws IOException { if (inputStream == null) { throw new IllegalArgumentException("InputStream should never be null, missing resource?"); } try { final Map<IRI, IRI> mappings = new HashMap<IRI, IRI>(); for (String line : IOUtils.readLines(inputStream)) { if (line.startsWith("#")) { continue; } String[] toks = line.split(" ", 2); if (toks.length != 2) { throw new IOException("Each line must have 1 space: "+line); } mappings.put(IRI.create(toks[0]), IRI.create(toks[1])); } return mappings; } finally { inputStream.close(); } }
Example #8
Source File: MgiGAFOWLBridgeTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testConversionToIndividuals() throws Exception{ ParserWrapper pw = new ParserWrapper(); OWLOntology ont = pw.parse(getResourceIRIString("go_xp_predictor_test_subset.obo")); OWLGraphWrapper g = new OWLGraphWrapper(ont); g.addSupportOntology(pw.parse(getResourceIRIString("gorel.owl"))); GafObjectsBuilder builder = new GafObjectsBuilder(); GafDocument gafdoc = builder.buildDocument(getResource("mgi-exttest.gaf")); GAFOWLBridge bridge = new GAFOWLBridge(g); bridge.setGenerateIndividuals(false); OWLOntology gafOnt = g.getManager().createOntology(); bridge.setTargetOntology(gafOnt); bridge.setBasicAboxMapping(true); bridge.translate(gafdoc); OWLDocumentFormat owlFormat = new RDFXMLDocumentFormat(); g.getManager().saveOntology(gafOnt, owlFormat, IRI.create(new File("target/gaf-abox.owl"))); for (OWLAxiom ax : gafOnt.getAxioms()) { //LOG.info("AX:"+ax); } }
Example #9
Source File: QueryArgumentTest.java From sparql-dl-api with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testIsVar() { QueryArgument arg = new QueryArgument(new Var("x")); assertTrue(arg.isVar()); QueryArgument arg2 = new QueryArgument(IRI.create("http://example.com")); assertFalse(arg2.isVar()); }
Example #10
Source File: InverseOfTautologyTest.java From SciGraph with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); String uri = Resources.getResource("ontologies/cases/TestInverseOfTautology.owl").toURI().toString(); IRI iri = IRI.create(uri); manager.loadOntologyFromOntologyDocument(iri); OWLOntologyWalker walker = new OWLOntologyWalker(manager.getOntologies()); MappedProperty mappedProperty = new MappedProperty(NodeProperties.LABEL); List<String> properties = new ArrayList<String>(); properties.add("http://www.w3.org/2000/01/rdf-schema#label"); properties.add("http://www.w3.org/2004/02/skos/core#prefLabel"); mappedProperty.setProperties(properties); ArrayList<MappedProperty> mappedPropertyList = new ArrayList<MappedProperty>(); mappedPropertyList.add(mappedProperty); GraphOwlVisitor visitor = new GraphOwlVisitor(walker, graph, mappedPropertyList); walker.walkStructure(visitor); Map<String, String> categories = new HashMap<>(); try (Transaction tx = graphDb.beginTx()) { OwlPostprocessor postprocessor = new OwlPostprocessor(graphDb, categories); postprocessor.processCategories(categories); postprocessor.processSomeValuesFrom(); tx.success(); } }
Example #11
Source File: AbstractOWLOntologyLoader.java From BioSolr with Apache License 2.0 | 5 votes |
@Override public Collection<String> getAccessions(IRI ontologyTermIRI) { Set<String> accessions = new HashSet<>(); accessions.add(getOntologyTermAccessions().get(ontologyTermIRI)); Optional<String> oboId = getOBOid(getOntologyTermAccessions().get(ontologyTermIRI)); if (oboId.isPresent()) { accessions.add(oboId.get()); } return accessions; }
Example #12
Source File: QueryAtomTest.java From sparql-dl-api with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testGetType() { QueryArgument arg = new QueryArgument(IRI.create("http://example.com")); QueryAtom atom = new QueryAtom(QueryAtomType.CLASS, arg); assertEquals(atom.getType(), QueryAtomType.CLASS); }
Example #13
Source File: OwlSimVariance.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private List<String> findRefURIs(double varValue, Map<IRI, Double> iResult) { List<String> list = new ArrayList<String>(); for (IRI iri : iResult.keySet()) { if (iResult.get(iri).doubleValue() == varValue) { list.add(iri.toString()); } } return list; }
Example #14
Source File: NCBIOWL.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Setup the alternative identifier annotation property. * * @param ontology * @return annotation property * * @see NCBIOWL#addAltId(OWLOntology, String, String, OWLAnnotationProperty) */ public static OWLAnnotationProperty setupAltIdProperty(OWLOntology ontology) { IRI iri = Obo2Owl.trTagToIRI(OboFormatTag.TAG_ALT_ID.getTag()); OWLAnnotationProperty ap = createAnnotationProperty(ontology, iri); OWLAnnotationProperty prop = dataFactory.getRDFSLabel(); OWLLiteral value = dataFactory.getOWLLiteral(Obo2OWLVocabulary.hasAlternativeId.getLabel()); manager.addAxiom(ontology, dataFactory.getOWLAnnotationAssertionAxiom(prop, iri, value)); return ap; }
Example #15
Source File: Sim2CommandRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@CLIMethod("--sim-save-ic-cache") public void simSaveICCache(Opts opts) throws Exception { opts.info("OUTFILE", "saves ICs as RDF/turtle cache"); if (owlsim == null) { owlsim = getOwlSimFactory().createOwlSim(g.getSourceOntology()); owlsim.createElementAttributeMapFromOntology(); } OWLOntology o = owlsim.cacheInformationContentInOntology(); TurtleDocumentFormat fmt = new TurtleDocumentFormat(); fmt.setPrefix("obo", "http://purl.obolibrary.org/obo/"); fmt.setPrefix("sim", "http://owlsim.org/ontology/"); g.getManager().saveOntology(o, fmt, IRI.create(opts.nextFile())); }
Example #16
Source File: AbstractOWLOntologyLoader.java From BioSolr with Apache License 2.0 | 5 votes |
@Override public Map<IRI, Collection<String>> getAnnotations(IRI entityIRI) { if (termAnnotations.containsKey(entityIRI)) { return termAnnotations.get(entityIRI); } return Collections.emptyMap(); }
Example #17
Source File: TransformationUtils.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected static IRI getSkolemIRI(List<OWLEntity> objs) { // IRI iri; StringBuffer sb = new StringBuffer(); for (OWLEntity obj : objs) { sb.append("_"+getFragmentID(obj)); } iri = IRI.create("http://x.org"+sb.toString()); return iri; }
Example #18
Source File: BioChebiGenerator.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void appendOntologyId(OWLOntologyID ontologyID, StringBuilder sb) { Optional<IRI> ontologyIRI = ontologyID.getOntologyIRI(); if (ontologyIRI.isPresent()) { sb.append("Ontology(id=").append(ontologyIRI.get()); Optional<IRI> versionIRI = ontologyID.getVersionIRI(); if (versionIRI .isPresent()) { sb.append(", version=").append(versionIRI.get()); } sb.append(")"); } else { sb.append("Ontology with no ID"); } }
Example #19
Source File: NCBIConverter.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the NCBI Taxonomy ID of an OWL Class. * * @param taxon the class * @return null or the NCBI Taxonomy ID as a string */ public static String getTaxonID(OWLClass taxon) { IRI iri = taxon.getIRI(); String iriString = iri.toString(); if (iriString.startsWith(NCBI)) { return iriString.replaceFirst("^" + NCBI, ""); } else { return null; } }
Example #20
Source File: AbstractOWLOntologyLoader.java From BioSolr with Apache License 2.0 | 5 votes |
protected Optional<String> getShortForm(IRI entityIRI) { getLog().trace("Attempting to extract fragment name of URI '" + entityIRI + "'"); String termURI = entityIRI.toString(); URI entUri = entityIRI.toURI(); // we want the "final part" of the URI... if (!StringUtils.isEmpty(entUri.getFragment())) { // a uri with a non-null fragment, so use this... getLog().trace("Extracting fragment name using URI fragment (" + entUri.getFragment() + ")"); return Optional.of(entUri.getFragment()); } else if (entityIRI.toURI().getPath() != null) { // no fragment, but there is a path so try and extract the final part... if (entityIRI.toURI().getPath().contains("/")) { getLog().trace("Extracting fragment name using final part of the path of the URI"); return Optional.of(entityIRI.toURI().getPath().substring(entityIRI.toURI().getPath().lastIndexOf('/') + 1)); } else { // no final path part, so just return whole path getLog().trace("Extracting fragment name using the path of the URI"); return Optional.of(entityIRI.toURI().getPath()); } } else { // no fragment, path is null, we've run out of rules so don't shorten getLog().trace("No rules to shorten this URI could be found (" + termURI + ")"); return Optional.empty(); } }
Example #21
Source File: OWLInAboxTranslator.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private OWLObjectPropertyExpression trTypeLevel(IRI iri) { IRI tlrIRI; if (isPreserveObjectPropertyIRIs) { tlrIRI = iri; } else { tlrIRI = IRI.create(iri.toString()+"TLR"); } return getOWLDataFactory().getOWLObjectProperty(tlrIRI); }
Example #22
Source File: OntologyHelper.java From BioSolr with Apache License 2.0 | 5 votes |
private Collection<String> findPropertyValueStrings(List<String> propertyUris, IRI iri) { Collection<String> classNames = new HashSet<>(); OWLDataFactory odf = ontology.getOWLOntologyManager().getOWLDataFactory(); // For every property URI, find the annotations for this entry propertyUris.parallelStream().map(uri -> odf.getOWLAnnotationProperty(IRI.create(uri))) .map(prop -> findAnnotationNames(iri, prop)).forEach(classNames::addAll); return classNames; }
Example #23
Source File: LocalMirrorIRIMapperTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testParseCatalogXML() throws Exception { File resource = getResource("owl-mirror.txt"); InputStream inputStream = new FileInputStream(resource); File parentFolder = resource.getParentFile(); Map<IRI, IRI> mappings = LocalMirrorIRIMapper.parseDirectoryMappingFile(inputStream, parentFolder); assertTrue(mappings.size() == 2); }
Example #24
Source File: OntologyHelper.java From BioSolr with Apache License 2.0 | 5 votes |
/** * Retrieve a map of related classes for a particular class. * * @param owlClass * @return a map of relation type to a list of IRIs for nodes with that * relationship. */ public Map<String, List<String>> getRestrictions(OWLClass owlClass) { RestrictionVisitor visitor = new RestrictionVisitor(Collections.singleton(ontology)); for (OWLSubClassOfAxiom ax : ontology.getSubClassAxiomsForSubClass(owlClass)) { OWLClassExpression superCls = ax.getSuperClass(); // Ask our superclass to accept a visit from the RestrictionVisitor // - if it is an existential restriction then our restriction visitor // will answer it - if not our visitor will ignore it superCls.accept(visitor); } Map<String, List<String>> restrictions = new HashMap<>(); for (OWLObjectSomeValuesFrom val : visitor.getSomeValues()) { OWLClassExpression exp = val.getFiller(); // Get the shortname of the property expression String shortForm = null; Set<OWLObjectProperty> signatureProps = val.getProperty().getObjectPropertiesInSignature(); for (OWLObjectProperty sigProp : signatureProps) { Collection<String> labels = findLabels(sigProp.getIRI()); if (labels.size() > 0) { shortForm = new ArrayList<String>(labels).get(0); } } if (shortForm != null && !exp.isAnonymous()) { IRI iri = exp.asOWLClass().getIRI(); if (!restrictions.containsKey(shortForm)) { restrictions.put(shortForm, new ArrayList<String>()); } restrictions.get(shortForm).add(iri.toString()); } } return restrictions; }
Example #25
Source File: OWLGraphWrapperBasic.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #26
Source File: SatisfiabilityChecker.java From SciGraph with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntology ont = manager.loadOntology(IRI.create(args[0])); ReasonerConfiguration config = new ReasonerConfiguration(); config.setFactory(ElkReasonerFactory.class.getCanonicalName()); ReasonerUtil util = new ReasonerUtil(config, manager, ont); Collection<OWLOntologyChange> removals = util.removeUnsatisfiableClasses(); if (!removals.isEmpty()) { logger.info("Removed " + removals.size() + " to help prevent unsatisfiable classes."); for (OWLOntologyChange removal: removals) { logger.info(removal.toString()); } } OWLReasoner reasoner = util.getReasoner(); if (!reasoner.isConsistent()) { logger.severe("Ontology is inconsistent"); System.exit(1); } Collection<OWLClass> unsatisfiableClasses = util.getUnsatisfiableClasses(); if (!unsatisfiableClasses.isEmpty()) { logger.severe("Ontology is unsatisfiable"); for (OWLClass unsatisfiableClass: unsatisfiableClasses) { logger.severe(unsatisfiableClass.toString()); } System.exit(2); } logger.info("Ontology is consistent and satisfiable"); System.exit(0); }
Example #27
Source File: VowlSearcher.java From OWL2VOWL with MIT License | 5 votes |
public VowlClass getIntersection(Collection<IRI> intersectionIris) { checkConsistenty(); for (VowlClass intersection : intersections) { if (intersection.getElementOfIntersection().containsAll(intersectionIris)) { return intersection; } } return null; }
Example #28
Source File: GraphOwlVisitor.java From SciGraph with Apache License 2.0 | 5 votes |
long getObjectPropertyRelationship( OWLPropertyAssertionAxiom<OWLObjectPropertyExpression, OWLIndividual> axiom) { long subject = getOrCreateNode(getIri(axiom.getSubject())); String property = getIri(axiom.getProperty()); long object = getOrCreateNode(getIri(axiom.getObject())); RelationshipType type = RelationshipType.withName(property.toString()); long relationship = getOrCreateRelationship(subject, object, type); graph.setRelationshipProperty(relationship, CommonProperties.IRI, property.toString()); return relationship; }
Example #29
Source File: OwlSimPValue.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public PValue getPValue(Set<OWLClass> candidates, IRI referenceEntity) throws OwlSimVarianceEntityReferenceNotFoundException { if (!refBasedStats.getReferenceStats().containsKey(referenceEntity)) { throw new OwlSimVarianceEntityReferenceNotFoundException(referenceEntity); } // Create IC list for candidates provided double[] icData = refBasedStats.retrieveCandidatesIC(candidates); List<double[]> sets = new ArrayList<double[]>(); sets.add(icData); sets.add(refBasedStats.getReferenceStats().get(referenceEntity).getValues()); return new PValue(TestUtils.tTest(refBasedStats.getReferenceStats().get(referenceEntity).getMean(), icData), TestUtils.oneWayAnovaPValue(sets), TestUtils.kolmogorovSmirnovStatistic(icData, refBasedStats.getReferenceStats().get(referenceEntity).getValues())); }
Example #30
Source File: VowlData.java From OWL2VOWL with MIT License | 5 votes |
public VowlObjectProperty getObjectPropertyForIri(IRI iri) { if (objectPropertyMap.containsKey(iri)) { return objectPropertyMap.get(iri); } else { throw new IllegalStateException("Can't find object property for passed iri: " + iri); } }