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