Search in sources :

Example 26 with Individual

use of org.apache.jena.ontology.Individual in project answer-ontology-construction by YueHub.

the class CompanyConstructionServiceImpl method construction.

@Override
public boolean construction(BaikePage baikePage) throws Exception {
    // 词条标题(实体名)
    String individualName = baikePage.getLemmaTitle();
    String polysemantExplain = baikePage.getPolysemantExplain();
    String url = baikePage.getUrl();
    Individual companyIndividual = null;
    // 查询词典中是否有该实体 有则查询返回 没有则创建返回  true表示这是本名
    companyIndividual = this.queryIndividual(individualName, polysemantExplain, url, true, OntologyClassEnum.COMPANY);
    constructionDAO.addObjectProperty(companyIndividual, "是", companyIndividual);
    // 添加数据属性(描述和歧义说明)
    String lemmaSummary = baikePage.getLemmaSummary();
    String picSrc = baikePage.getPicSrc();
    if (picSrc != null) {
        // 取得当前时间
        long times = System.currentTimeMillis();
        // 生成0-1000的随机数
        int random = (int) (Math.random() * 1000);
        // 扩展名称
        String newPicName = times + "" + random + ".jpg";
        PictureDownloader.picDownload(picSrc, newPicName, Config.picSavePath + File.separator + OntologyClassEnum.COMPANY.getName());
        constructionDAO.addDataProperty(companyIndividual, "picSrc", newPicName);
    }
    constructionDAO.addDataProperty(companyIndividual, "URL信息来源", url);
    constructionDAO.addDataProperty(companyIndividual, "描述", lemmaSummary);
    constructionDAO.addDataProperty(companyIndividual, "歧义说明", polysemantExplain);
    // 添加基本信息
    List<String> parameterNamesFilter = baikePage.getParameterNames();
    List<String> parameterValuesFilter = baikePage.getParameterValues();
    constructionDAO.addDataProperties(companyIndividual, parameterNamesFilter, parameterValuesFilter);
    return false;
}
Also used : Individual(org.apache.jena.ontology.Individual)

Example 27 with Individual

use of org.apache.jena.ontology.Individual in project incubator-sdap-mudrod by apache.

the class OwlParser method parseClass.

protected void parseClass(OntClass cls, List<Object> occurs, int depth) {
    // dont deal with anonymous classes
    if (cls.isAnon()) {
        return;
    }
    // add cls to Ontology searchterms
    // list labels
    Iterator<?> labelIter = cls.listLabels(null);
    // if has no labels
    if (!labelIter.hasNext()) {
        // add rdf:ID as a label
        cls.addLabel(rdfidToLabel(cls.getLocalName()), null);
    }
    // reset the label iterator
    labelIter = cls.listLabels(null);
    while (labelIter.hasNext()) {
        Literal l = (Literal) labelIter.next();
        ((LocalOntology) ont).addSearchTerm(l.toString(), cls);
    }
    // recurse to the next level down
    if (cls.canAs(OntClass.class) && !occurs.contains(cls)) {
        // list subclasses
        for (Iterator<?> i = cls.listSubClasses(true); i.hasNext(); ) {
            OntClass sub = (OntClass) i.next();
            // we push this expression on the occurs list before we recurse
            occurs.add(cls);
            parseClass(sub, occurs, depth + 1);
            occurs.remove(cls);
        }
        // list instances
        for (Iterator<?> i = cls.listInstances(); i.hasNext(); ) {
            // add search terms for each instance
            // list labels
            Individual individual = (Individual) i.next();
            for (Iterator<?> j = individual.listLabels(null); j.hasNext(); ) {
                Literal l = (Literal) j.next();
                ((LocalOntology) ont).addSearchTerm(l.toString(), individual);
            }
        }
    }
}
Also used : Individual(org.apache.jena.ontology.Individual) Literal(org.apache.jena.rdf.model.Literal) OntClass(org.apache.jena.ontology.OntClass)

Example 28 with Individual

use of org.apache.jena.ontology.Individual in project incubator-sdap-mudrod by apache.

the class LocalOntology method subclasses.

/**
 * Retrieve all subclasses of entity(ies) hashed to searchTerm
 * @param entitySearchTerm a query (keywords) for which to obtain
 * subclasses.
 * @return an {@link java.util.Iterator} containing the subclass as Strings.
 */
@Override
public Iterator<String> subclasses(String entitySearchTerm) {
    Map<OntResource, String> classMap = retrieve(entitySearchTerm);
    Map<String, String> subclasses = new HashMap<>();
    Iterator<OntResource> iter = classMap.keySet().iterator();
    while (iter.hasNext()) {
        OntResource resource = iter.next();
        if (resource instanceof OntClass) {
            // need to pass the .listSubClasses(true) boolean parameter.
            for (Iterator<?> i = ((OntClass) resource).listSubClasses(); i.hasNext(); ) {
                OntResource subclass = (OntResource) i.next();
                for (Iterator<?> j = subclass.listLabels(null); j.hasNext(); ) {
                    Literal l = (Literal) j.next();
                    subclasses.put(l.toString(), "1");
                }
            }
            // get individuals
            for (Iterator<?> i = ((OntClass) resource).listInstances(); i.hasNext(); ) {
                OntResource subclass = (OntResource) i.next();
                for (Iterator<?> j = subclass.listLabels(null); j.hasNext(); ) {
                    Literal l = (Literal) j.next();
                    subclasses.put(l.toString(), "1");
                }
            }
        } else if (resource instanceof Individual) {
            for (Iterator<?> i = resource.listSameAs(); i.hasNext(); ) {
                OntResource subclass = (OntResource) i.next();
                for (Iterator<?> j = subclass.listLabels(null); j.hasNext(); ) {
                    Literal l = (Literal) j.next();
                    subclasses.put(l.toString(), "1");
                }
            }
        }
    }
    return subclasses.keySet().iterator();
}
Also used : HashMap(java.util.HashMap) Individual(org.apache.jena.ontology.Individual) Literal(org.apache.jena.rdf.model.Literal) Iterator(java.util.Iterator) OntResource(org.apache.jena.ontology.OntResource) OntClass(org.apache.jena.ontology.OntClass)

Example 29 with Individual

use of org.apache.jena.ontology.Individual in project incubator-sdap-mudrod by apache.

the class LocalOntology method renderHierarchy.

protected static void renderHierarchy(PrintStream out, OntClass cls, List<Object> occurs, int depth) {
    renderClassDescription(out, cls, depth);
    out.println();
    // recurse to the next level down
    if (cls.canAs(OntClass.class) && !occurs.contains(cls)) {
        for (Iterator<?> i = cls.listSubClasses(true); i.hasNext(); ) {
            OntClass sub = (OntClass) i.next();
            // we push this expression on the occurs list before we recurse
            occurs.add(cls);
            renderHierarchy(out, sub, occurs, depth + 1);
            occurs.remove(cls);
        }
        for (Iterator<?> i = cls.listInstances(); i.hasNext(); ) {
            Individual individual = (Individual) i.next();
            renderURI(out, individual.getModel(), individual.getURI());
            out.print(" [");
            for (Iterator<?> j = individual.listLabels(null); j.hasNext(); ) {
                out.print(((Literal) j.next()).getString() + ", ");
            }
            out.print("] ");
            out.println();
        }
    }
}
Also used : Individual(org.apache.jena.ontology.Individual) Literal(org.apache.jena.rdf.model.Literal) OntClass(org.apache.jena.ontology.OntClass)

Example 30 with Individual

use of org.apache.jena.ontology.Individual in project jena by apache.

the class TestFileManager method testFileManagerReadOntModel.

@Test
public void testFileManagerReadOntModel() {
    OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
    FileManager.getInternal().readModelInternal(model, testingDir + "/data.ttl");
    // Check
    Individual ind = model.getIndividual("http://example.com/individual");
    String t = ind.getOntClass().getURI();
    assertEquals("http://example.com/T", t);
    long c1 = model.size();
    model.loadImports();
    long c2 = model.size();
    assertEquals(c1, c2);
}
Also used : Individual(org.apache.jena.ontology.Individual) OntModel(org.apache.jena.ontology.OntModel) Test(org.junit.Test)

Aggregations

Individual (org.apache.jena.ontology.Individual)53 ArrayList (java.util.ArrayList)17 OntClass (org.apache.jena.ontology.OntClass)16 Literal (org.apache.jena.rdf.model.Literal)6 OntModel (org.apache.jena.ontology.OntModel)4 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 MediaType (javax.ws.rs.core.MediaType)2 ObjectProperty (org.apache.jena.ontology.ObjectProperty)2 OntResource (org.apache.jena.ontology.OntResource)2 Test (org.junit.Test)2 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Model (org.apache.jena.rdf.model.Model)1 Resource (org.apache.jena.rdf.model.Resource)1 Address (org.orcid.jaxb.model.message.Address)1 Email (org.orcid.jaxb.model.message.Email)1 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)1 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1