Search in sources :

Example 21 with OntClass

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

the class CharacterConstructionServiceImpl method dealProfession.

/**
 * 处理职业
 * @param baikePage
 * @return
 */
public boolean dealProfession(Individual characterIndividual, BaikePage baikePage) {
    int index = 0;
    List<String> professionList = new ArrayList<String>();
    for (String parameterName : baikePage.getParameterNames()) {
        if (parameterName.equals("职业")) {
            professionList = StringFilter.parameterValueSeparates(baikePage.getParameterValues().get(index));
            for (String profession : professionList) {
                OntClass professionClass = constructionDAO.getOntClass(profession);
                // 如果本体中此时没有该二级类
                if (professionClass == null) {
                    professionClass = constructionDAO.createOntClass(profession);
                }
                // 获取一级类 人物类
                OntClass characterClass = constructionDAO.getOntClass(OntologyClassEnum.CHARACTER.getName());
                // 创建子类(二级类)
                constructionDAO.addSubClass(characterClass, professionClass);
                constructionDAO.addSubClass(characterIndividual, professionClass);
            }
        }
        ++index;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) OntClass(org.apache.jena.ontology.OntClass)

Example 22 with OntClass

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

the class OwlParser method parse.

/**
 * Parse OWL ontology files using Apache Jena
 */
@Override
public void parse(Ontology ont, OntModel m) {
    this.ont = ont;
    for (Iterator<OntClass> i = rootClasses(m); i.hasNext(); ) {
        OntClass c = i.next();
        // dont deal with anonymous classes
        if (c.isAnon()) {
            continue;
        }
        parseClass(c, new ArrayList<>(), 0);
    }
}
Also used : OntClass(org.apache.jena.ontology.OntClass)

Example 23 with OntClass

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

the class LocalOntology method synonyms.

/**
 * Retreives synonyms for an given phrase if the phrase
 * is present in the ontology
 * @param queryKeyPhrase an input string representing a phrase
 * for which we wish to obtain synonyms.
 * @return an {@link java.util.Iterator} containing synonyms string tokens
 * or an empty if no synonyms exist for the given queryKeyPhrase.
 */
@Override
public Iterator synonyms(String queryKeyPhrase) {
    Map<?, ?> classMap = retrieve(queryKeyPhrase);
    Map<Object, Object> synonyms = new HashMap<>();
    Iterator<?> iter = classMap.keySet().iterator();
    while (iter.hasNext()) {
        OntResource resource = (OntResource) iter.next();
        // listLabels
        for (Iterator<?> i = resource.listLabels(null); i.hasNext(); ) {
            Literal l = (Literal) i.next();
            synonyms.put(l.toString(), "1");
        }
        if (resource instanceof Individual) {
            // get all individuals same as this one
            for (Iterator<?> i = resource.listSameAs(); i.hasNext(); ) {
                Individual individual = (Individual) i.next();
                // add labels
                for (Iterator<?> j = individual.listLabels(null); j.hasNext(); ) {
                    Literal l = (Literal) i.next();
                    synonyms.put(l.toString(), "1");
                }
            }
        } else if (resource instanceof OntClass) {
            // list equivalent classes
            for (Iterator<?> i = ((OntClass) resource).listEquivalentClasses(); i.hasNext(); ) {
                OntClass equivClass = (OntClass) i.next();
                // add labels
                for (Iterator<?> j = equivClass.listLabels(null); j.hasNext(); ) {
                    Literal l = (Literal) j.next();
                    synonyms.put(l.toString(), "1");
                }
            }
        }
    }
    return synonyms.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 24 with OntClass

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

the class TestOntTools method testNamedHierarchyRoots1.

public void testNamedHierarchyRoots1() {
    m_a.addSubClass(m_b);
    m_b.addSubClass(m_c);
    m_c.addSubClass(m_d);
    m_e.addSubClass(m_e);
    m_e.addSubClass(m_f);
    OntClass anon0 = m_model.createClass();
    anon0.addSubClass(m_a);
    anon0.addSubClass(m_e);
    List<OntClass> nhr = OntTools.namedHierarchyRoots(m_model);
    assertEquals(3, nhr.size());
    assertTrue(nhr.contains(m_a));
    assertTrue(nhr.contains(m_e));
    assertTrue(nhr.contains(m_g));
}
Also used : OntClass(org.apache.jena.ontology.OntClass)

Example 25 with OntClass

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

the class TestOntTools method testNamedHierarchyRoots2.

public void testNamedHierarchyRoots2() {
    OntClass anon0 = m_model.createClass();
    OntClass anon1 = m_model.createClass();
    anon0.addSubClass(m_a);
    anon0.addSubClass(m_e);
    anon0.addSubClass(anon1);
    anon1.addSubClass(m_g);
    m_a.addSubClass(m_b);
    m_b.addSubClass(m_c);
    m_c.addSubClass(m_d);
    m_e.addSubClass(m_e);
    m_e.addSubClass(m_f);
    List<OntClass> nhr = OntTools.namedHierarchyRoots(m_model);
    assertEquals(3, nhr.size());
    assertTrue(nhr.contains(m_a));
    assertTrue(nhr.contains(m_e));
    assertTrue(nhr.contains(m_g));
}
Also used : OntClass(org.apache.jena.ontology.OntClass)

Aggregations

OntClass (org.apache.jena.ontology.OntClass)26 Individual (org.apache.jena.ontology.Individual)16 ArrayList (java.util.ArrayList)5 Literal (org.apache.jena.rdf.model.Literal)4 OntResource (org.apache.jena.ontology.OntResource)3 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 ThreadInfo (java.lang.management.ThreadInfo)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 ExecutorService (java.util.concurrent.ExecutorService)1 OntModel (org.apache.jena.ontology.OntModel)1 InfModel (org.apache.jena.rdf.model.InfModel)1 Model (org.apache.jena.rdf.model.Model)1 Resource (org.apache.jena.rdf.model.Resource)1 StmtIterator (org.apache.jena.rdf.model.StmtIterator)1 JenaException (org.apache.jena.shared.JenaException)1 ExtendedIterator (org.apache.jena.util.iterator.ExtendedIterator)1