本文整理汇总了Java中com.hp.hpl.jena.ontology.Individual.listOntClasses方法的典型用法代码示例。如果您正苦于以下问题:Java Individual.listOntClasses方法的具体用法?Java Individual.listOntClasses怎么用?Java Individual.listOntClasses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.ontology.Individual
的用法示例。
在下文中一共展示了Individual.listOntClasses方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClassesOf
import com.hp.hpl.jena.ontology.Individual; //导入方法依赖的package包/类
@Override
public Set<OntClass> getClassesOf(OntResource resource, boolean onlyDirect) throws NotFoundException {
Set<OntClass> result = new HashSet<OntClass>();
Individual individual = null;
try {
individual = resource.asIndividual();
}
catch (ConversionException ce) {
throw new NotFoundException(Namespaces.toLightString(resource) + " is not an individual!");
}
ExtendedIterator<OntClass> it = individual.listOntClasses(onlyDirect);
while (it.hasNext())
{
OntClass tmp = it.next();
if (tmp != null && !tmp.isAnon()){
result.add(tmp);
}
}
if (onlyDirect)
Logger.demo_nodes("Retrieving direct classes of " + Namespaces.toLightString(resource), result);
else
Logger.demo_nodes("Retrieving all classes of " + Namespaces.toLightString(resource), result);
return result;
}
示例2: individualToSadl
import com.hp.hpl.jena.ontology.Individual; //导入方法依赖的package包/类
private String individualToSadl(ModelConcepts concepts, Individual inst, boolean embeddedBNode) {
StringBuilder sb = new StringBuilder();
boolean bnode = false;
if (inst.isURIResource()) {
sb.append(individualNameAndAnnotations(concepts, inst));
if (isNewLineAtEndOfBuffer(sb)) {
sb.append(" ");
}
sb.append(" is a ");
}
else {
sb.append("(a ");
bnode = true;
}
ExtendedIterator<OntClass> eitr = inst.listOntClasses(true);
int itercnt = 0;
boolean intersectionClass = false;
while (eitr.hasNext()) {
try {
OntClass cls = eitr.next();
if (itercnt == 0) {
if (eitr.hasNext()) {
intersectionClass = true;
}
if (intersectionClass) {
sb.append("{");
}
}
if (itercnt++ > 0 && eitr.hasNext()) {
sb.append(" or ");
}
sb.append(uriToSadlString(concepts, cls));
}
catch (Exception e){
System.err.println(e.getMessage());
}
}
if (intersectionClass) {
sb.append("}");
}
StmtIterator insitr = inst.listProperties();
while (insitr.hasNext()) {
Statement s = insitr.next();
if (s.getPredicate().equals(RDF.type) || s.getPredicate().equals(RDFS.label) || s.getPredicate().equals(RDFS.comment)) {
continue;
}
if (embeddedBNode) {
sb.append("\n with ");
}
else {
sb.append("\n has ");
}
sb.append(uriToSadlString(concepts, s.getPredicate()));
sb.append(" ");
sb.append(rdfNodeToSadlString(concepts, s.getObject(), false));
}
if (bnode) {
sb.append(")");
}
else {
addEndOfStatement(sb, 1);
}
return sb.toString();
}
示例3: addIndividuals
import com.hp.hpl.jena.ontology.Individual; //导入方法依赖的package包/类
private void addIndividuals(List<Individual> instlst) throws Exception {
Individual inst;
for (int i = 0; instlst != null && i < instlst.size(); i++) {
inst = instlst.get(i);
if (shouldResourceBeOutput(inst, true, false, true)) {
ExtendedIterator<OntClass> typeitr = inst.listOntClasses(true);
if (typeitr.hasNext()) {
List<OntClass> types = new ArrayList<OntClass>();
while (typeitr.hasNext()) {
try {
OntClass type = typeitr.next();
types.add(type);
}
catch (Exception e) {
ExtendedIterator<Resource> eitr = inst.listRDFTypes(true);
while (eitr.hasNext()) {
Resource rtype = eitr.next();
if (!rtype.isAnon()) {
OntClass newClass = theBaseModel.createClass(rtype.getURI());
types.add(newClass);
}
}
}
}
String typeString = classListToString(types, null);
if (inst.isAnon()) {
sadlModel.append("A ");
sadlModel.append(typeString);
}
else {
sadlModel.append(resourceToString(inst, false));
sadlModel.append(" is a ");
sadlModel.append(typeString);
}
String instProps = instancePropertiesToString(inst, false, 1);
if (instProps != null) {
sadlModel.append(instProps);
}
addEndOfStatement(sadlModel, 1);
resourcesOutput.add(inst);
}
else {
throw new Exception("The instance '" + inst.toString() + "' does not have a specified type (class); SADL cannot import it.");
}
}
}
}