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;
}
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);
}
}
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();
}
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));
}
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));
}
Aggregations