Java Jena排序元素
早上好 我目前正在为我制作的本体开发一个查看器。我想根据元素的类型对元素(OnProperty、ObjectProperty、Individuals等)着色。 以下是我实现这一目标的想法:Java Jena排序元素,java,jena,apache-jena,Java,Jena,Apache Jena,早上好 我目前正在为我制作的本体开发一个查看器。我想根据元素的类型对元素(OnProperty、ObjectProperty、Individuals等)着色。 以下是我实现这一目标的想法: public Paint transform(RDFNode i) { if(OntProperty) return Color.RED; if(ObjectProperty) return Color.BLUE; if(Individuals) return Color.GREEN;
public Paint transform(RDFNode i) {
if(OntProperty) return Color.RED;
if(ObjectProperty) return Color.BLUE;
if(Individuals) return Color.GREEN;
return Color.GRAY;
}
我用JenaJung图书馆来做这个
问题是我没有找到ifs的正确条件。有人有主意吗
谢谢大家。这是我找到的解决方案
@Override
public Paint transform(RDFNode i) {
OntModel model = (OntModel) i.getModel();
Collection classes = JenaJungGraph.asCollection(model.listClasses());
if(classes.stream().anyMatch(x -> x.toString() == i.asResource().toString())) return ontPropertyColor;
return Color.GRAY;
}
等等,对于其他元素
希望这能帮助别人
asCollection()
函数用于将迭代器组成集合
static <T> Collection<T> asCollection(final ClosableIterator<? extends T> it) {
Collection<T> toReturn = new HashSet<>();
while (it.hasNext())
if(true)
toReturn.add((T) it.next());
it.close();
return toReturn;
}
静态采集A采集(最终ClosableIterator