2015-01-14 2 views
1

Учитывая произвольный IRI, такой как основная онтология или одна из онтологий, которые он импортирует, я хотел бы извлечь заголовок, но код не содержит аннотаций.OWL API, извлечение строки из URI

Вот пример того, что я говорю о том, из онтологии SKOS:

<owl:Ontology rdf:about="http://www.w3.org/2004/02/skos/core"> 
    <dct:title xml:lang="en">SKOS Vocabulary</dct:title> 

Как точно бы извлечь, «SKOS словарь».

Вот какой-то код, который я использую сейчас в учебнике OWL-API.

public void testingOWL() throws OWLOntologyCreationException, OWLOntologyStorageException 
{ 

// Get hold of an ontology manager 
OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); 

// Load an ontology from the Web. We load the ontology from a document IRI 
IRI docIRI = IRI.create("http://www.w3.org/2009/08/skos-reference/skos.rdf"); 
OWLOntology skos = manager.loadOntologyFromOntologyDocument(docIRI); 

System.out.println("Loaded ontology: " + skos); 
System.out.println(); 

// Save a local copy of the ontology. (Specify a path appropriate to your setup) 
File file = new File("e:/downloadAndSaveOWLFile.owl"); 
manager.saveOntology(skos, IRI.create(file.toURI())); 

// Ontologies are saved in the format from which they were loaded. 
// We can get information about the format of an ontology from its manager 
OWLOntologyFormat format = manager.getOntologyFormat(skos); 
System.out.println(" format: " + format); 
System.out.println(); 

// Save the ontology in owl/xml format 
OWLXMLOntologyFormat owlxmlFormat = new OWLXMLOntologyFormat(); 

// Some ontology formats support prefix names and prefix IRIs. 
// In our case we loaded the pizza ontology from an rdf/xml format, which supports prefixes. 
// When we save the ontology in the new format we will copy the prefixes over 
// so that we have nicely abbreviated IRIs in the new ontology document 
if(format.isPrefixOWLOntologyFormat()) 
{ 
    owlxmlFormat.copyPrefixesFrom(format.asPrefixOWLOntologyFormat()); 
} 

manager.saveOntology(skos, owlxmlFormat, IRI.create(file.toURI())); 

// Dump an ontology to System.out by specifying a different OWLOntologyOutputTarget 
// Note that we can write an ontology to a stream in a similar way 
// using the StreamOutputTarget class 
OWLOntologyDocumentTarget documentTarget = new SystemOutDocumentTarget(); 

// Try another format - The Manchester OWL Syntax 
ManchesterOWLSyntaxOntologyFormat manSyntaxFormat = new ManchesterOWLSyntaxOntologyFormat(); 

if(format.isPrefixOWLOntologyFormat()) 
{ 
    manSyntaxFormat.copyPrefixesFrom(format.asPrefixOWLOntologyFormat()); 
} 
manager.saveOntology(skos, manSyntaxFormat, documentTarget); 
} 

EDIT: обновите код, основываясь на приведенном ниже предложении, но возвращает только 1 объект для rdfs: seeAlso.

общественной недействительная GetData() бросает OWLOntologyCreationException

{ 
    // Get hold of an ontology manager 
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); 

    // Load an ontology from the Web. We load the ontology from a document IRI 
    IRI docIRI = IRI.create("http://www.w3.org/2009/08/skos-reference/skos.rdf"); 
    OWLOntology skos = manager.loadOntologyFromOntologyDocument(docIRI); 

    for (OWLAnnotation ann: skos.getAnnotations()) 
    { 
     System.out.println("ann: " + ann.getProperty()); 
     System.out.println(); 
    } 


} 

ответ

0

аннотаций вы ищете онтологию аннотация, то есть IRI, что является его предметом является онтологией самой IRI. Доступ к нему осуществляется иначе, чем стандартные аннотации.

OWLOntology o= ... // init the ontology as usual 
for (OWLAnnotation ann: o.getAnnotations()){ 
    if(ann.getProperty().equals(dataFactory.getRDFSLabel()){ 
     // here you have found a rdfs:label annotation, so you can use the value for your purposes 
    } 
} 

Редактировать: Пример использования

public static void main(String[] args) throws OWLOntologyCreationException { 
    OWLOntologyManager m = OWLManager.createOWLOntologyManager(); 
    OWLOntology o = m.loadOntology(IRI 
      .create("http://www.w3.org/2009/08/skos-reference/skos.rdf")); 
    for (OWLAnnotation a : o.getAnnotations()) { 
     System.out.println("TestSkos.main() " + a); 
    } 
} 
Output: 

    TestSkos.main() Annotation(rdfs:seeAlso <http://www.w3.org/TR/skos-reference/>) 
    TestSkos.main() Annotation(<http://purl.org/dc/terms/creator> "Alistair Miles") 
    TestSkos.main() Annotation(<http://purl.org/dc/terms/description> "An RDF vocabulary for describing the basic structure and content of concept schemes such as thesauri, classification schemes, subject heading lists, taxonomies, 'folksonomies', other types of controlled vocabulary, and also concept schemes embedded in glossaries and terminologies."@en) 
    TestSkos.main() Annotation(<http://purl.org/dc/terms/contributor> "Participants in W3C's Semantic Web Deployment Working Group.") 
    TestSkos.main() Annotation(<http://purl.org/dc/terms/creator> "Sean Bechhofer") 
    TestSkos.main() Annotation(<http://purl.org/dc/terms/contributor> "Nikki Rogers") 
    TestSkos.main() Annotation(<http://purl.org/dc/terms/title> "SKOS Vocabulary"@en) 
    TestSkos.main() Annotation(<http://purl.org/dc/terms/contributor> "Dave Beckett") 
+1

К сожалению, код выше, дает только один аннотаций, который предназначен для RDFS: seeAlso. Он не находит Словарь SKOS. –

+0

Какую версию API OWL вы используете? Я их всех получаю. См. Обновленный фрагмент. – Ignazio

+0

Я использовал версию 3. ** но я переключился на 4. ** и он отлично работает. Благодаря! –

Смежные вопросы