Jena - 排序元素

Jena - Sort elements

大家早上好,

我目前正在为我制作的本体开发一个查看器。我想根据元素的类型为元素(OntPropery、ObjectProperty、Individuals 等)着色。 这是我实现这个的想法:

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()函数用于将Iterator组成Collection

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;
}