0

Morning all,

I'm currently developing a viewer for the ontologies I made. I want to colorize the elements (OntPropery, ObjectProperty, Individuals, …) based on their types. Here is my idea to implement this :

public Paint transform(RDFNode i) {
    if(OntProperty) return Color.RED;
    if(ObjectProperty) return Color.BLUE;
    if(Individuals) return Color.GREEN;
    return Color.GRAY;
}

I use the JenaJung libraries for this.

The problem is that I don’t find the correct condition for the ifs. Does anybody have an idea ?

Thx for all.

Ignazio
  • 10,504
  • 1
  • 14
  • 25
Gilles-Antoine Nys
  • 1,481
  • 16
  • 21

1 Answers1

1

Here is the solution I found !

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

And so on, for the others elements.

Hope that will help somebody else !

The asCollection() function is used to form the Iterator into 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;
}
Gilles-Antoine Nys
  • 1,481
  • 16
  • 21