Java Code Examples for org.semanticweb.owlapi.model.IRI#toString()
The following examples show how to use
org.semanticweb.owlapi.model.IRI#toString() .
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: Similarity.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected String[] splitIRI(IRI x) { String s = x.toString(); String id = null; if (s.startsWith(Obo2OWLConstants.DEFAULT_IRI_PREFIX)) { id = s.replaceAll(Obo2OWLConstants.DEFAULT_IRI_PREFIX, ""); return new String[]{Obo2OWLConstants.DEFAULT_IRI_PREFIX,id}; } for (String del : new String[]{"#","/",":"}) { if (s.contains(del)) { String[] r = s.split(del,2); r[0] = r[0]+del; return r; } } return new String[]{"",s}; }
Example 2
Source File: AbstractSimPreProcessor.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public IRI makeViewClassIRI(IRI vcIRI, IRI vpIRI, String sep, boolean isUseOriginalClassIRIs, boolean isAssumeOBOStyleIRIs) { if (!isUseOriginalClassIRIs) { String vcIRIstr = vcIRI.toString(); if (isAssumeOBOStyleIRIs) { String baseId = Owl2Obo.getIdentifier(vcIRI); String relId = Owl2Obo.getIdentifier(vpIRI); vcIRIstr = Obo2OWLConstants.DEFAULT_IRI_PREFIX + baseId.replace(":", "_") + sep + relId.replace("_", "-").replace(":", "-"); } else { String frag = vpIRI.getFragment(); if (frag == null || frag.equals("")) { frag = vpIRI.toString().replaceAll(".*\\/", "view"); } vcIRIstr = vcIRIstr + sep + frag; } vcIRI = IRI.create(vcIRIstr); } return vcIRI; }
Example 3
Source File: PropertyViewOntologyBuilder.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public IRI makeViewClassIRI(IRI vcIRI, IRI vpIRI, String sep) { if (!isUseOriginalClassIRIs) { String vcIRIstr = vcIRI.toString(); if (isAssumeOBOStyleIRIs) { String baseId = Owl2Obo.getIdentifier(vcIRI); String relId = Owl2Obo.getIdentifier(vpIRI); vcIRIstr = Obo2OWLConstants.DEFAULT_IRI_PREFIX + baseId.replace(":", "_") + sep + relId.replace("_", "-").replace(":", "-"); } else { String frag = vpIRI.getFragment(); if (frag == null || frag.equals("")) { frag = vpIRI.toString().replaceAll(".*\\/", "view"); } vcIRIstr = vcIRIstr + sep + frag; } vcIRI = IRI.create(vcIRIstr); } return vcIRI; }
Example 4
Source File: OntologyHelper.java From BioSolr with Apache License 2.0 | 5 votes |
private Optional<String> getShortForm(IRI entityIRI) { LOGGER.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... LOGGER.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("/")) { LOGGER.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 LOGGER.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 LOGGER.trace("No rules to shorten this URI could be found (" + termURI + ")"); return Optional.empty(); } }
Example 5
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 6
Source File: CURIEShortFormProvider.java From robot with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the short form of an IRI as a CURIE. * * @param iri IRI to get short form of * @return CURIE */ public String getShortForm(IRI iri) { String iriString = iri.toString(); // Find the first (longest) match from sorted prefix/ns entries for (Map.Entry<String, String> prefix2Ns : sortedPrefixMap) { String prefix = prefix2Ns.getKey() + ":"; String ns = prefix2Ns.getValue(); if (iriString.startsWith(ns)) { return iriString.replace(ns, prefix); } } // Could not match, just return full IRI logger.error("Unable to find namespace for: " + iri); return iriString; }
Example 7
Source File: NCBI2OWLTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private String expandAnnotation(String subject, String property, IRI value) { RDFXMLDocumentFormat format = OWLConverter.format; // TODO: Why is "Annotation" always doubled? return "AnnotationAssertion(<" + format.getIRI(property) + "> <" + format.getIRI(subject) + "> <" + value.toString() + ">)"; }
Example 8
Source File: SnomedPrefixManager.java From snomed-owl-toolkit with Apache License 2.0 | 5 votes |
@Override public String getPrefixIRI(IRI iri) { Map<String, String> prefixName2PrefixMap = getPrefixName2PrefixMap(); String iriString = iri.toString(); for (Map.Entry<String, String> namePrefixEntry : prefixName2PrefixMap.entrySet()) { if (iriString.startsWith(namePrefixEntry.getValue())) { return namePrefixEntry.getKey() + iriString.substring(namePrefixEntry.getValue().length()); } } return null; }
Example 9
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 10
Source File: ImportClosureSlurper.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
static String createLocalFileName(IRI iri) { String iriString = iri.toString(); iriString = iriString.replaceFirst("http://", "").replaceFirst("https://", ""); iriString = iriString.replace(':', '_'); iriString = iriString.replace('\\', '_'); return iriString; }
Example 11
Source File: ImportChainDotWriter.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
private CharSequence nodeId(IRI iri) { String iriString = iri.toString(); return quote(iriString); }
Example 12
Source File: AbstractOWLOntologyLoader.java From BioSolr with Apache License 2.0 | 4 votes |
/** * Extracts and loads into memory all the class labels and corresponding IRIs. This class makes the assumption that * one primary label per class exists. If any classes contain multiple rdfs:labels, these classes are ignored. * <p> * Once loaded, this method must set the IRI of the ontology, and should add class labels, class types (however you * chose to implement the concept of a "type") and synonyms, where they exist. * <p> * Implementations do not need to concern themselves with resolving imports or physical/logical mappings as this is * done in initialisation at the abstract level. Subclasses can simply do <code>OWLOntology ontology = * getManager().loadOntology(IRI.create(getOntologyURI()));</code> as a basic implementation before populating the * various required caches */ protected OWLOntology loadOntology() throws OWLOntologyCreationException { try { getLog().debug("Loading ontology..."); this.ontology = getManager().loadOntology(getOntologyIRI()); IRI ontologyIRI = ontology.getOntologyID().getOntologyIRI(); if (getOntologyName() == null) { String name = getShortForm(ontologyIRI).get(); if (name == null) { getLog().warn("Can't shorten the name for " + ontologyIRI.toString()); name = ontologyIRI.toString(); } setOntologyName(name); } getLog().debug("Successfully loaded ontology " + ontologyIRI); this.provider = new AnnotationValueShortFormProvider( Collections.singletonList(factory.getOWLAnnotationProperty(getLabelIRI())), Collections.<OWLAnnotationProperty, List<String>>emptyMap(), manager); this.manSyntaxRenderer = new ManchesterOWLSyntaxOWLObjectRendererImpl(); manSyntaxRenderer.setShortFormProvider(provider); // this call will initialise the reasoner getOWLReasoner(ontology); // cache all URIs for classes, properties and individuals getLog().debug("Computing indexes..."); Collection<OWLEntity> allEntities = new HashSet<>(); for (OWLOntology ontology1 : manager.getOntologies()) { allEntities.addAll(ontology1.getSignature()); } indexTerms(allEntities); return ontology; } finally { getLog().debug("Done loading/indexing"); } }
Example 13
Source File: LegoDotWriter.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
private CharSequence nodeId(IRI iri) { String iriString = iri.toString(); return quote(iriString); }
Example 14
Source File: LegoShuntGraphTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
private String nodeId(IRI iri) { return iri.toString(); }
Example 15
Source File: OWLGraphWrapperExtended.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
public IRI getIRIByIdentifier(String id, boolean isAutoResolve) { if (isAutoResolve) { OWLObject obj = this.getObjectByAltId(id); if (obj != null) { return ((OWLNamedObject) obj).getIRI(); } } // special magic for finding IRIs from a non-standard identifier // This is the case for relations (OWLObject properties) with a short hand // or for relations with a non identifiers with-out a colon, e.g. negative_regulation // we first collect all candidate matching properties in candIRISet. Set<IRI> candIRISet = Sets.newHashSet(); if (!id.contains(":")) { final OWLAnnotationProperty shortHand = getDataFactory().getOWLAnnotationProperty(Obo2OWLVocabulary.IRI_OIO_shorthand.getIRI()); final OWLAnnotationProperty oboIdInOwl = getDataFactory().getOWLAnnotationProperty(Obo2Owl.trTagToIRI(OboFormatTag.TAG_ID.getTag())); for (OWLOntology o : getAllOntologies()) { for(OWLObjectProperty p : o.getObjectPropertiesInSignature()) { // check for short hand or obo ID in owl Set<OWLAnnotation> annotations = OwlHelper.getAnnotations(p, o); if (annotations != null) { for (OWLAnnotation owlAnnotation : annotations) { OWLAnnotationProperty property = owlAnnotation.getProperty(); if ((shortHand != null && shortHand.equals(property)) || (oboIdInOwl != null && oboIdInOwl.equals(property))) { OWLAnnotationValue value = owlAnnotation.getValue(); if (value != null && value instanceof OWLLiteral) { OWLLiteral literal = (OWLLiteral) value; String shortHandLabel = literal.getLiteral(); if (id.equals(shortHandLabel)) { candIRISet.add(p.getIRI()); } } } } } } } } // In the case where we find multiple candidate IRIs, we give priorities for IRIs from BFO or RO ontologies. IRI returnIRI = null; for (IRI iri: candIRISet) { String iriStr = iri.toString(); if (iriStr.contains("BFO") || iriStr.contains("RO")) { returnIRI = iri; } } // If we were not able to find RO/BFO candidate IRIs for id if (returnIRI == null) { // We return it only if we have only one candidate. if (candIRISet.size() == 1) return new ArrayList<IRI>(candIRISet).get(0); // This is the unexpected case. Multiple non-RO/BPO properties are mapped to given id and it's not clear what to return. else if (candIRISet.size() > 1) throw new RuntimeException("Multiple candidate IRIs are found for id: " + id + ". None of them are from BFO or RO."); } // If we were able to find the property from RO/BFO, just return it. else { return returnIRI; } // otherwise use the obo2owl method Obo2Owl b = new Obo2Owl(getManager()); // re-use manager, creating a new one can be expensive as this is a highly used code path b.setObodoc(new OBODoc()); return b.oboIdToIRI(id); }
Example 16
Source File: OwlSimVarianceEntityReferenceNotFoundException.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
public OwlSimVarianceEntityReferenceNotFoundException(IRI referenceEntity) { super("Reference entity does not exist: " + referenceEntity.toString()); }
Example 17
Source File: Reporter.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void printOWLObject(OWLObject obj, String del) { String id; if (obj instanceof OWLNamedObject) { IRI iri = ((OWLNamedObject)obj).getIRI(); if (iri.getFragment() != null) { id = iri.getFragment(); } else { id = iri.toString(); id = id.replaceAll(".*/", ""); } } else { /* if (obj instanceof OWLObjectIntersectionOf) { s.print("and"); for (OWLClassExpression sx : ((OWLObjectIntersectionOf)x).getOperands()) { printX(s, sx, depth+1); } } else if (x instanceof OWLObjectUnionOf) { s.print("or"); for (OWLClassExpression sx : ((OWLObjectUnionOf)x).getOperands()) { printX(s, sx, depth+1); } } else if (x instanceof OWLQuantifiedRestriction) { OWLQuantifiedRestriction qr = (OWLQuantifiedRestriction)x; s.print(qr.getProperty().toString()+" "+qr.getClassExpressionType()); printX(s, qr.getFiller(), depth+1); } */ // todo - show class expressions id = obj.toString(); } printStream.print(id); String label = graph.getLabel(obj); if (label == null) { label = ""; } printStream.print(del); printStream.print("\'"+label+"\'"); }
Example 18
Source File: OwlConverter.java From elk-reasoner with Apache License 2.0 | 4 votes |
@SuppressWarnings("static-method") public ElkIri convert(IRI iri) { return new ElkFullIri(iri.toString()); }
Example 19
Source File: MirrorOperation.java From robot with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Generates a local file path that should be in a 1:1 relationship with the ontology IRI. * * <p>The path can the point to a file that mirrors an individual ontology * * @param iri The IRI of the ontology. * @return path */ private static String getMirrorPathOfOntologyIRI(IRI iri) { String iriString = iri.toString(); iriString = iriString.replaceFirst("http://", "").replaceFirst("https://", ""); iriString = iriString.replace(':', '_'); iriString = iriString.replace('\\', '_'); return iriString; }