gpt4 book ai didi

java - 我无法访问对象属性

转载 作者:行者123 更新时间:2023-11-30 05:51:59 24 4
gpt4 key购买 nike

我正在使用 Java 和 Jena API。我有一个 class Marriage,它有 3 个对象属性,分别称为“hasHusband”、“Haswife”和“结婚日期”。前两个与 class Person 相关联,它具有 hasFirstNamehasLastNamedateOfBirth 等数据类型属性....

我想访问对象属性“Haswife”和“hasHusband”,然后是妻子的名字和丈夫的名字。

这是我的 rdf 文件中的表示方式:

(...)

  <j.0:FAMmariage rdf:about=http://www.fam.com/FAM#BrunoCatherine> 

<j.0:FAMaDateMariage>25/07/2011</j.0:FAMaDateMariage>

<j.0:FAMhasWife>
<rdf:Description rdf:about="http://www.fam.com/FAM#Catherine20/03/1982">
<j.0:FAMDateOfBirth>20/03/1980</j.0:FAMDateOfBirth>
<j.0:FAMHasName>Gomez</j.0:FAMHasName>
<j.0:FAMHasFirstName>Catherine</j.0:FAMHasFirstName>
</rdf:Description>
</j.0:FAMHasWife>

<j.0:FAMHusband>
<rdf:Description rdf:about="http://www.fam.com/FAM# Bruno15/06/1980 ">
<j.0:FAMaDateOfBirth>15/06/1980 </j.0:FAMDateOfBirth>
<j.0:FAMHasName>Jeandet </j.0:FAMHasName>
<j.0:FAMHasFirstName>Bruno</j.0:FAMHasFirstName>
</rdf:Description>
</j.0:FAMHusband>

</j.0:FAMmariage>
(...)

我试过了,还是不行:

StmtIterator iter = onto.model.listStatements();  
while (iter.hasNext()) {
Statement stmt = iter.nextStatement();
Resource subject = stmt.getSubject();
Property predicate = stmt.getPredicate();
RDFNode object = stmt.getObject();
if (predicate.equals(onto.hasWife))
{
System.out.print(" " + object.toString() + " ");
}
}

你能告诉我哪里出了问题吗?

谢谢

已编辑

更多有用的细节:

(...)

person = model.createClass(uriBase+"person");
person.addSubClass(man);
person.addSubClass(woman);
marriage = model.createClass(uriBase+"marriage");

(...)

hasHusband = model.createObjectProperty(uriBase+"hasHusband");
hasHusband.setDomain(marriage);
hasHusband.setRange(man);

hasWife = model.createObjectProperty(uriBase+"hasWife");
hasWife.setDomain(marriage);
hasWife.setRange(woman);

hasFirstName = model.createDatatypeProperty(uriBase+"hasFirstName");
hasFirstName.setDomain(person);
hasFirstName.setRange(XSD.xstring);

(...)

最佳答案

那行得通吗?

ont.hasWife=model.createProperty("your namespace URI here","FAMhasWife");

StmtIterator iter = onto.model.listStatements(null,onto.hasWife,(RDFNode)null);
while (iter.hasNext()) {
Statement stmt = iter.nextStatement();

System.out.print(stmt.getObject().toString());
}

关于java - 我无法访问对象属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12192915/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com