Search code examples
javardfsesamelinked-datastardog

How can you exclude certain POJO properties from being mapped to RDF with Complexible Pinto?


I am trying out Complexible Pinto for mapping between Java POJOs and RDF. In one of my evaluation tests, I have a derived property that should not appear in the output triples, however it seems that all JavaBean getters are automatically included in the output with a generated property resource. How can I suppress this without mangling the method name? Similar frameworks typically have some kind of @Ignore annotation or an an ignore annotation parameter, but I do not see one in Pinto.

I can suppress this by mangling the method name (e.g. xgetNameLength()), but I would prefer not to do it that way, since that would be ugly.


Code:

I create a Java POJO that has a derived property that should not be mapped, and convert it to triples using Pinto.

package pintoeval;

import org.openrdf.model.Graph;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
import org.openrdf.model.impl.URIImpl;
import org.openrdf.rio.RDFFormat;
import org.openrdf.rio.RDFWriter;
import org.openrdf.rio.Rio;

import com.complexible.pinto.Identifiable;
import com.complexible.pinto.RDFMapper;
import com.complexible.pinto.annotations.RdfProperty;
import com.complexible.pinto.annotations.RdfsClass;

public class PintoStackOverflowQuestion {

    @RdfsClass("http://www.example.com/person")
    public static class Person implements Identifiable {
        private Resource id;
        private String name;


        @Override
        public Resource id() {
            return id;
        }

        @Override
        public void id(Resource arg0) {
            id = arg0;
        }

        public String getName() {
            return name;
        }

        @RdfProperty("http://www.example.com/personName")
        public void setName(String name) {
            this.name = name;
        }

        /*
         * This is directly derived from another value, so it should not be stored.
         */
        public int getNameLength() {
            return name.length();
        }
    }

    public static void main(String[] args) throws Exception {
        Person person = new Person();
        person.id(new URIImpl("http://www.example.com/person/Larry0384"));
        person.setName("Larry");

        Graph aGraph = RDFMapper.create().writeValue(person);

        RDFWriter writer = Rio.createWriter(RDFFormat.NTRIPLES, System.out);
        writer.startRDF();
        for (Statement s : aGraph) {
            writer.handleStatement(s);
        }
        writer.endRDF();
    }
}

Output:

The derived value is mapped with a generated property. I would like to exclude it, so only two triples would be created.

<http://www.example.com/person/Larry0384> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/person> .
<http://www.example.com/person/Larry0384> <tag:complexible:pinto:nameLength> "5"^^<http://www.w3.org/2001/XMLSchema#int> .
<http://www.example.com/person/Larry0384> <http://www.example.com/personName> "Larry"^^<http://www.w3.org/2001/XMLSchema#string> .

Solution

  • As Jeen suggested, Pinto doesn't current offer this capability. But this was on my mental todo list, so I created an issue for this.