简体   繁体   English

我该如何找回 <oboInOwl:hasExactSynonym> 从每个 <rdf:Description> 使用OWL API

[英]How can I retrieve <oboInOwl:hasExactSynonym> from every <rdf:Description> using OWL API

I am new to OWL API hence I am facing some issues for retrieving data. 我是OWL API的新手,因此我在检索数据时遇到一些问题。

Suppose I have the following data: 假设我有以下数据:

 <rdf:Description rdf:about="http://purl.obolibrary.org/obo/GO_0044297"> <oboInOwl:creation_date>"2010-02-05T10:37:16Z"</oboInOwl:creation_date> <obo:IAO_0000115>"The portion of a cell bearing surface projections such as axons, dendrites, cilia, or flagella that includes the nucleus, but excludes all cell projections."</obo:IAO_0000115> <oboInOwl:hasOBONamespace>"cellular_component"</oboInOwl:hasOBONamespace> <oboInOwl:hasDbXref>"Wikipedia:Cell_body"</oboInOwl:hasDbXref> <oboInOwl:hasDbXref>"FMA:67301"</oboInOwl:hasDbXref> <oboInOwl:hasExactSynonym>"cell soma"</oboInOwl:hasExactSynonym> <rdfs:label>"cell body"</rdfs:label> <rdfs:subClassOf>http://purl.obolibrary.org/obo/GO_0044464</rdfs:subClassOf> <oboInOwl:hasDbXref>"FBbt:00005107"</oboInOwl:hasDbXref> <rdf:type>http://www.w3.org/2002/07/owl#Class</rdf:type> <oboInOwl:id>"GO:0044297"</oboInOwl:id> <rdfs:comment>"Note that 'cell body' and 'cell soma' are not used in the literature for cells that lack projections, nor for some cells (eg yeast with mating projections) that do have projections."</rdfs:comment> <oboInOwl:created_by>"xyz"</oboInOwl:created_by> <oboInOwl:inSubset>http://purl.obolibrary.org/obo/go#goslim_pir</oboInOwl:inSubset> </rdf:Description> <rdf:Description rdf:about="http://purl.obolibrary.org/obo/GO_0071509"> <oboInOwl:hasRelatedSynonym>"activation of MAPKK activity involved in mating response"</oboInOwl:hasRelatedSynonym> <rdfs:subClassOf>http://purl.obolibrary.org/obo/GO_0090028</rdfs:subClassOf> <oboInOwl:hasOBONamespace>"biological_process"</oboInOwl:hasOBONamespace> <oboInOwl:hasExactSynonym>"activation of MAP kinase kinase activity during conjugation with cellular fusion"</oboInOwl:hasExactSynonym> <oboInOwl:hasExactSynonym>"conjugation with cellular fusion, activation of MAPKK activity"</oboInOwl:hasExactSynonym> <rdfs:label>"activation of MAPKK activity involved in conjugation with cellular fusion"</rdfs:label> <rdf:type>http://www.w3.org/2002/07/owl#Class</rdf:type> <oboInOwl:id>"GO:0071509"</oboInOwl:id> <oboInOwl:creation_date>"2010-01-05T02:09:58Z"</oboInOwl:creation_date> <oboInOwl:hasExactSynonym>"conjugation with cellular fusion, activation of MAP kinase kinase activity"</oboInOwl:hasExactSynonym> <oboInOwl:created_by>"midori"</oboInOwl:created_by> <obo:IAO_0000115>"Any process that initiates the activity of the inactive enzyme MAP kinase kinase in the context of conjugation with cellular fusion."</obo:IAO_0000115> <rdfs:subClassOf>http://purl.obolibrary.org/obo/GO_0000186</rdfs:subClassOf> </rdf:Description> 

For each of the "rdf:description" I want to retrieve its corresponding "rdf:label", "oboInOwl:hasExactSynonym" and "rdfs:subClassOf" using OWL API in java. 对于每个“ rdf:description”,我想使用Java中的OWL API检索其对应的“ rdf:label”,“ oboInOwl:hasExactSynonym”和“ rdfs:subClassOf”。

So far I can get all labels but not the linkages as to which label is for which description. 到目前为止,我可以获取所有标签,但无法获得关于哪个标签用于哪个描述的链接。

Currently my code looks like: 目前,我的代码如下:

OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        OWLOntology pizzaOntology = manager.loadOntologyFromOntologyDocument(f);
        Set<OWLOntology> allOntologies = manager.getImportsClosure(pizzaOntology);
        //System.out.println(allOntologies);
        OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
        OWLReasoner reasoner = reasonerFactory.createReasoner(pizzaOntology);
        //pizzaOntology
        OWLDataFactory factory = manager.getOWLDataFactory();

        Set<OWLAxiom> axiom = pizzaOntology.getAxioms();
        for (OWLAxiom o : axiom) {
            AxiomType<?> at = o.getAxiomType();
            //System.out.println("Annotation type is "+at+" for "+o);

            if (at == AxiomType.ANNOTATION_ASSERTION) {
                OWLAnnotationAssertionAxiom ax = (OWLAnnotationAssertionAxiom) o;
                //Check if the axiom is a label and write to file
                if(ax.getProperty().toString().contains("hasExactSynonym"))
                System.out.println("Data is "+ax.getValue().toString());
                if (ax.getProperty().equals(factory.getRDFSLabel())) {
                    String label = ax.getValue().toString();
                    label = label.toLowerCase();
                    label = label.replaceAll("[^\\p{L}\\p{Nd}]+", " ");
                    allLabels.add(label);
                }
            }

        }

Can someone help me with some ideas about this? 有人可以帮我一些想法吗?

This should help: 这应该有助于:

    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology pizzaOntology = manager.loadOntologyFromOntologyDocument(f);
    Set<OWLOntology> allOntologies = manager.getImportsClosure(pizzaOntology);
    // System.out.println(allOntologies);
    OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
    OWLReasoner reasoner = reasonerFactory.createReasoner(pizzaOntology);
    // pizzaOntology
    OWLDataFactory factory = manager.getOWLDataFactory();
    Map<OWLAnnotationSubject, String> allLabels = new HashMap<>();
    Map<OWLAnnotationSubject, String> allExactSynonyms = new HashMap<>();
    for (OWLAnnotationAssertionAxiom ax : pizzaOntology
        .getAxioms(AxiomType.ANNOTATION_ASSERTION)) {
        // Check if the axiom is a label and write to file
        OWLAnnotationSubject subject = ax.getSubject();
        if (ax.getProperty().toString().contains("hasExactSynonym")) {
            allExactSynonyms.put(subject, ax.getValue().toString());
        }
        if (ax.getProperty().equals(factory.getRDFSLabel())) {
            String label = ax.getValue().toString();
            label = label.toLowerCase();
            label = label.replaceAll("[^\\p{L}\\p{Nd}]+", " ");
            allLabels.put(subject, label);
        }
    }

The two maps hold the relation between an IRI (the annotation subject in this case is always an IRI - annotation are attached to IRIs of classes, not to classes themselves) and the value of a property. 这两个映射保持IRI(在这种情况下,注释主体始终是IRI-注释附加到类的IRI,而不是类本身)与属性值之间的关系。 If you match the label value with the value of a property for an IRI, you can find the other value through the IRI in the map. 如果将标签值与IRI的属性值匹配,则可以通过IRI在地图中找到其他值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM