Java 如何排除某些POJO属性映射到具有复杂Pinto的RDF?
我正在尝试Java POJO和RDF之间的映射。在我的一个评估测试中,我有一个派生属性,它不应该出现在输出三元组中,但是似乎所有JavaBean getter都会自动包含在输出中,并带有一个生成的属性资源。如何在不损坏方法名称的情况下抑制此操作?类似的框架通常有某种@Ignore注释或Ignore注释参数,但我在Pinto中没有看到 我可以通过修改方法名(例如,Java 如何排除某些POJO属性映射到具有复杂Pinto的RDF?,java,rdf,sesame,linked-data,stardog,Java,Rdf,Sesame,Linked Data,Stardog,我正在尝试Java POJO和RDF之间的映射。在我的一个评估测试中,我有一个派生属性,它不应该出现在输出三元组中,但是似乎所有JavaBean getter都会自动包含在输出中,并带有一个生成的属性资源。如何在不损坏方法名称的情况下抑制此操作?类似的框架通常有某种@Ignore注释或Ignore注释参数,但我在Pinto中没有看到 我可以通过修改方法名(例如,xgetNameLength())来抑制这种情况,但我不希望这样做,因为那样会很难看 代码: 我创建了一个具有不应映射的派生属性的Ja
xgetNameLength()
)来抑制这种情况,但我不希望这样做,因为那样会很难看
代码: 我创建了一个具有不应映射的派生属性的JavaPOJO,并使用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();
}
}
输出:
派生值与生成的属性映射。我想排除它,所以只会创建两个三元组
<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> .
。
"5"^^ .
“拉里”^^。
正如吉恩建议的那样,Pinto目前不提供这种功能。但是这在我的心理待办事项列表中,所以我创建了一个。Try@RdfProperty(null)
-这行吗?我尝试过了,但是我得到了这个编译错误注释属性RdfProperty.value的值必须是一个常量表达式。如果我定义将某个实际字符串常量设置为null并使用该常量,则会出现相同的错误。请尝试使用@RdfProperty(“”
)代替。您还可以尝试创建一个长度设置器(该设置器抛出一个不支持操作异常
),但该设置器没有@RdfProperty
注释仍然不起作用。我已经尝试过一些直接的潜在魔法值,但没有一个有效。查看代码中读取该值的位置,您建议的两个值都显式等效于无注释。