本文整理汇总了Java中org.semanticweb.owlapi.model.IRI类的典型用法代码示例。如果您正苦于以下问题:Java IRI类的具体用法?Java IRI怎么用?Java IRI使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IRI类属于org.semanticweb.owlapi.model包,在下文中一共展示了IRI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLabelFromBuiltIn
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
private String getLabelFromBuiltIn(String uri){
try {
IRI iri = IRI.create(URLDecoder.decode(uri, "UTF-8"));
// if IRI is built-in entity
if(iri.isReservedVocabulary()) {
// use the short form
String label = sfp.getShortForm(iri);
// if it is a XSD numeric data type, we attach "value"
if(uri.equals(XSD.nonNegativeInteger.getURI()) || uri.equals(XSD.integer.getURI())
|| uri.equals(XSD.negativeInteger.getURI()) || uri.equals(XSD.decimal.getURI())
|| uri.equals(XSD.xdouble.getURI()) || uri.equals(XSD.xfloat.getURI())
|| uri.equals(XSD.xint.getURI()) || uri.equals(XSD.xshort.getURI())
|| uri.equals(XSD.xbyte.getURI()) || uri.equals(XSD.xlong.getURI())
){
label += " value";
}
return label;
}
} catch (UnsupportedEncodingException e) {
logger.error("Getting short form of " + uri + "failed.", e);
}
return null;
}
示例2: getLabelFromBuiltIn
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
private String getLabelFromBuiltIn(String uri) {
try {
IRI iri = IRI.create(URLDecoder.decode(uri, "UTF-8"));
// if IRI is built-in entity
if (iri.isReservedVocabulary()) {
// use the short form
String label = sfp.getShortForm(iri);
// if it is a XSD numeric data type, we attach "value"
if (uri.equals(XSD.nonNegativeInteger.getURI()) || uri.equals(XSD.integer.getURI())
|| uri.equals(XSD.negativeInteger.getURI()) || uri.equals(XSD.decimal.getURI())
|| uri.equals(XSD.xdouble.getURI()) || uri.equals(XSD.xfloat.getURI())
|| uri.equals(XSD.xint.getURI()) || uri.equals(XSD.xshort.getURI())
|| uri.equals(XSD.xbyte.getURI()) || uri.equals(XSD.xlong.getURI())) {
label += " value";
}
return label;
}
} catch (UnsupportedEncodingException e) {
logger.error("Getting short form of " + uri + "failed.", e);
}
return null;
}
示例3: getMostSpecificType
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
/**
* Returns the most specific type of a given individual.
*
* @param ind
* @return
*/
private OWLClass getMostSpecificType(OWLIndividual ind) {
logger.debug("Getting the most specific type of " + ind);
String query = String.format("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ "select distinct ?type where {" + " <%s> a ?type ." + "?type rdfs:label []."
// + "?type a owl:Class ." // too strict, thus currently omitted
+ "filter not exists {?subtype ^a <%s> ; rdfs:subClassOf ?type .filter(?subtype != ?type)}}",
ind.toStringID(), ind.toStringID());
SortedSet<OWLClass> types = new TreeSet<OWLClass>();
QueryExecution qe = qef.createQueryExecution(query);
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
QuerySolution qs = rs.next();
if (qs.get("type").isURIResource()) {
types.add(new OWLClassImpl(IRI.create(qs.getResource("type").getURI())));
}
}
qe.close();
// of more than one type exists, we have to choose one
// TODO
return types.first();
}
示例4: getOntologyFromName
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
/**
* Open the OWL ontology (from the ontology resources of CartAGen) whose name
* is passed as parameter.
* @param name
* @return
* @throws OWLOntologyCreationException
*/
public static OWLOntology getOntologyFromName(String name)
throws OWLOntologyCreationException {
// create the URI from the name and the CartAGen ontologies folder path
String uri = FOLDER_PATH + "/" + name + ".owl";
InputStream stream = OwlUtil.class.getResourceAsStream(uri);
File file = new File(stream.toString());
String path = file.getAbsolutePath().substring(0,
file.getAbsolutePath().lastIndexOf('\\'));
path = path.replaceAll(new String("\\\\"), new String("//"));
path = path + "//src/main//resources//ontologies//" + name + ".owl";
// create the ontology from the URI using an OWLOntologyManager
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI physicalURI = IRI.create(new File(path));
OWLOntology ontology = manager
.loadOntologyFromOntologyDocument(physicalURI);
return ontology;
}
示例5: getOntology
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
/**
* @param filename
* @return
*/
private static OWLOntology getOntology(String filename) {
File file = new File(filename);
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
OWLOntology o;
try {
o = m.loadOntologyFromOntologyDocument(IRI.create(file.toURI()));
} catch (OWLOntologyCreationException e) {
fail("Cannot load ontology.");
return null;
}
assertNotNull(o);
return o;
}
示例6: getIndividuals
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
/**
* @param superclass
* @param o
* @return
*/
private static Set<OWLIndividual> getIndividuals(String superclass,
OWLOntology o) {
OWLReasoner reasoner = PelletReasonerFactory.getInstance()
.createReasoner(o);
Set<OWLNamedIndividual> instances = reasoner.getInstances(
OWL.Class(IRI.create(superclass)), false).getFlattened();
// filter out all owl:sameAs instances...
Set<OWLIndividual> ind = new TreeSet<>();
for (OWLNamedIndividual i : instances) {
ind.add(i);
}
logger.info("|I| = " + ind.size());
logger.debug("I = " + ind);
return ind;
}
示例7: parseDirectoryMappingFile
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
/**
* 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();
}
}
示例8: testDataPropertyMetadata
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
@Test
public void testDataPropertyMetadata() throws Exception {
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
OWLOntology ontology = m.createOntology(IRI.generateDocumentIRI());
{
// create a test ontology with one data property
OWLDataFactory f = m.getOWLDataFactory();
IRI propIRI = IRI.generateDocumentIRI();
OWLDataProperty prop = f.getOWLDataProperty(propIRI);
m.addAxiom(ontology, f.getOWLDeclarationAxiom(prop));
m.addAxiom(ontology, f.getOWLAnnotationAssertionAxiom(propIRI, f.getOWLAnnotation(f.getRDFSLabel(), f.getOWLLiteral("fake-data-property"))));
}
OWLGraphWrapper graph = new OWLGraphWrapper(ontology);
MolecularModelManager<?> mmm = createM3(graph);
Pair<List<JsonRelationInfo>,List<JsonRelationInfo>> pair = MolecularModelJsonRenderer.renderProperties(mmm, null, curieHandler);
List<JsonRelationInfo> dataProperties = pair.getRight();
assertEquals(1, dataProperties.size());
}
示例9: extractService
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
/**
* Extracts data manipulation service information from the ontology.
*
* @param service
* service individual found in ontology.
* @param ontology
* searched ontology.
* @return extracted data manipulation service.
* @throws EntryCreationException
* should any problems with extraction of data manipulation service information occur.
*/
private DataManipulationService extractService(OWLIndividual service, OWLOntology ontology)
throws EntryCreationException {
DataManipulationService dataManipulationService = new DataManipulationService();
Set<OWLIndividual> profiles = service.getObjectPropertyValues(ontologyManager.getOWLDataFactory()
.getOWLObjectProperty(PRESENTS_PROPERTY_IRI), ontology);
for (OWLIndividual profile : profiles) {
String profilePath = profile.asOWLNamedIndividual().getIRI().getStart();
profilePath = profilePath.substring(0, profilePath.length() - 1);
OWLOntology profileOntology = ontologyManager.getOntology(IRI.create(profilePath));
dataManipulationService.setIri(extractServiceIri(service));
dataManipulationService.setName(extractServiceName(profile, profileOntology));
dataManipulationService.setDescription(extractServiceDescription(profile, profileOntology));
dataManipulationService.setType(extractServiceType(profile, profileOntology));
}
return dataManipulationService;
}
示例10: addPTBoxConstraints
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
protected void addPTBoxConstraints(OWLOntology ontology, PTBox ptbox,
OWLOntologyManager manager, OWLDataFactory factory) {
ConceptConverter converter = new ConceptConverter(ptbox.getClassicalKnowledgeBase(), factory);
for (ConditionalConstraint cc : ptbox.getDefaultConstraints()) {
OWLAnnotationProperty annProp = factory.getOWLAnnotationProperty( IRI.create(Constants.CERTAINTY_ANNOTATION_URI ));
OWLAnnotationValue annValue = factory.getOWLStringLiteral( cc.getLowerBound() + ";" + cc.getUpperBound() );
OWLAnnotation annotation = factory.getOWLAnnotation( annProp, annValue );
OWLClassExpression clsEv = (OWLClassExpression)converter.convert( cc.getEvidence() );
OWLClassExpression clsCn = (OWLClassExpression)converter.convert( cc.getConclusion() );
OWLAxiom axiom = factory.getOWLSubClassOfAxiom( clsEv, clsCn, Collections.singleton( annotation ) );
try {
manager.applyChange( new AddAxiom(ontology, axiom) );
} catch( OWLOntologyChangeException e ) {
e.printStackTrace();
}
}
}
示例11: testUnsatifiabilityDueToClashInABoxAssertions
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
/**
* Atomic clash
*/
public void testUnsatifiabilityDueToClashInABoxAssertions() {
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLClassExpression expr1 = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "A")));
OWLClassExpression expr2 = factory.getOWLObjectComplementOf(expr1);
OWLNamedIndividual indiv = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "a")));
OWLIndividualAxiom fact1 = factory.getOWLClassAssertionAxiom(expr1, indiv);
OWLIndividualAxiom fact2 = factory.getOWLClassAssertionAxiom(expr2, indiv);
try {
OWLOntology ontology = manager.createOntology();
manager.addAxiom(ontology, fact1);
manager.addAxiom(ontology, fact2);
Wolpertinger wolpertinger = new Wolpertinger(ontology);
assertFalse(wolpertinger.isConsistent());
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
fail();
}
}
示例12: getModuleFromAxioms
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
/**
* Necessary toi construct a module for an arbitriary set of axioms
* @param moduleAxioms
* @param moduleUri
* @return
*/
public OWLOntology getModuleFromAxioms(Set<OWLAxiom> moduleAxioms, IRI moduleIri) {
OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
OWLOntology module=null;
try {
module = ontologyManager.createOntology(moduleIri);
List<OWLOntologyChange> ontoChanges = new ArrayList<OWLOntologyChange>();
for(OWLAxiom axiom : moduleAxioms) {
ontoChanges.add(new AddAxiom(module, axiom));
}
ontologyManager.applyChanges(ontoChanges);
}
catch(Exception e) {
System.out.println("Error creating module ontology from extende set of axioms.");
}
//System.out.println("Time create OWLOntology for module (s): " + (double)((double)fin-(double)init)/1000.0);
return module;
}
示例13: handleUnionOf
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
private void handleUnionOf(List<CheckWarning> warnings, Set<OWLOntology> allOntologies,
OWLEquivalentClassesAxiom axiom, OWLObjectUnionOf union, OWLPrettyPrinter pp)
{
List<OWLClassExpression> operands = union.getOperandsAsList();
for(OWLClassExpression operand : operands) {
if (!operand.isAnonymous()) {
OWLClass operandCls = operand.asOWLClass();
if (isDangling(operandCls, allOntologies)) {
final IRI iri = operandCls.getIRI();
String message = "Dangling reference "+iri+" in UNION_OF axiom: "+pp.render(axiom);
warnings.add(new CheckWarning(getID(), message , isFatal(), iri, OboFormatTag.TAG_UNION_OF.getTag()));
}
}
else {
// not translatable to OBO
handleGeneric(warnings, allOntologies, axiom, operand, pp);
}
}
}
示例14: resolveClassList
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
private Set<OWLClass> resolveClassList(Param p) {
Set<OWLClass> objs = new HashSet<OWLClass>();
if (getParams(p) != null) {
ArrayList<String> ids = new ArrayList<String>(Arrays.asList(getParams(p)));
LOG.info("Param "+p+" IDs: "+ids.toString());
for (String id : ids) {
// we allow resolution by altId, if present; in future we
// may want to check the altId map at this level so we can
// provide metadata in the payload about any mappings provided.
// See: https://github.com/monarch-initiative/monarch-app/issues/97
OWLClass c = graph.getOWLClassByIdentifier(id, true);
if (c == null) {
// TODO - strict mode - for now we include unresolvable classes
IRI iri = graph.getIRIByIdentifier(id);
c = graph.getDataFactory().getOWLClass(iri);
LOG.info("Unresolvable id:"+id+". Making temp class element:"+c.toString());
}
objs.add(c);
}
}
LOG.info("Num objs: "+objs.size());
return objs;
}
示例15: testSelfReferences
import org.semanticweb.owlapi.model.IRI; //导入依赖的package包/类
@Test
public void testSelfReferences() throws Exception {
ParserWrapper parser = new ParserWrapper();
IRI iri = IRI.create(getResource("verification/self_references.obo").getAbsoluteFile()) ;
OWLGraphWrapper graph = parser.parseToOWLGraph(iri.toString());
OntologyCheck check = new SelfReferenceInDefinition();
Collection<CheckWarning> warnings = check.check(graph, graph.getAllOWLObjects());
assertEquals(2, warnings.size());
for (CheckWarning warning : warnings) {
boolean found = false;
if (warning.getIris().contains(IRI.create("http://purl.obolibrary.org/obo/FOO_0004")) ||
warning.getIris().contains(IRI.create("http://purl.obolibrary.org/obo/FOO_0006"))) {
found = true;
}
assertTrue(found);
}
}