如何使用 Complexible Pinto 排除某些 POJO 属性被映射到 RDF?

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

我正在尝试 Complexible Pinto 在 Java POJO 和 RDF 之间进行映射。在我的一个评估测试中,我有一个不应出现在输出三元组中的派生 属性,但是似乎所有 JavaBean getter 都自动包含在输出中,并带有生成的 属性 资源。如何在不破坏方法名称的情况下抑制它?类似的框架通常有某种@Ignore 注释或忽略注释参数,但我在 Pinto 中没有看到。

我可以通过修改方法名称(例如 xgetNameLength())来抑制这种情况,但我不想那样做,因为那样会很丑陋。


代码:

我创建了一个 Java POJO,它具有不应映射的派生 属性,并使用 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 PintoWhosebugQuestion {

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

输出:

派生值映射到生成的 属性。我想排除它,所以只会创建两个三元组。

<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> .

正如 Jeen 所建议的,Pinto 目前不提供此功能。但这在我的待办事项清单上,所以我创建了一个 issue for this.