我正在使用 Eclipse 和 Jena 框架来开发 Web 应用程序。我的应用程序执行以下操作:
使用姓名、电子邮件、兴趣(C语言、Java等)、职业、用户名和密码等信息注册新用户。
此信息存储在名为 user.rdf 的 rdf 文件中。
使用新的所需用户名和密码创建一个新的用户帐户。新用户的登录根据用户的兴趣打开数据库中的所有相关书籍。
现在我需要向新用户推荐以下内容:
如果他/她对 C 语言感兴趣,则会向他推荐 C++ 书籍,并且可以将列表填充到屏幕上。
我知道这需要一个需要事实和规则的推理引擎。事实将在存储用户兴趣的 rdf 文件中。规则文件将根据推荐完成时的规则显示。
我有一个包含以下内容的 user.rdf 文件。
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:kb="http://protege.stanford.edu/kb#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Suresh">
<rdfs:label>Suresh</rdfs:label>
<kb:Uname>suresh</kb:Uname>
<kb:Password>suresh</kb:Password>
<kb:Occupation>Agent</kb:Occupation>
<kb:Interest>Java</kb:Interest>
<kb:Fname>Suresh</kb:Fname>
<kb:Email>suresh_345@yahoo.co.in</kb:Email>
<rdf:type rdf:resource="http://protege.stanford.edu/kb#USER"/>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Raj">
<kb:Email>ra@gmail.com</kb:Email>
<kb:Name>Raj</kb:Name>
<kb:Password>lkj</kb:Password>
<kb:Uname>raj</kb:Uname>
<kb:Interest>C Language</kb:Interest>
<kb:Occupation>Student</kb:Occupation>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Anvika">
<rdfs:label>Anvika</rdfs:label>
<kb:Uname>anu</kb:Uname>
<kb:Password>anu</kb:Password>
<kb:Occupation>Student</kb:Occupation>
<kb:Interest>C Language</kb:Interest>
<kb:Fname>Anvika</kb:Fname>
<kb:Email>anu@gmail.com</kb:Email>
<rdf:type rdf:resource="http://protege.stanford.edu/kb#USER"/>
</rdf:Description>
</rdf:RDF>
用户 Suresh 和 Anvika 实际上是在 Protege 中创建的,然后文件将通过应用程序使用其他用户详细信息进行更新。
test.rules 文件具有以下内容:
@prefix kb: http://protege.stanford.edu/kb#
[likec++: (?s rdf:type kb:LikeC++)
<-
(?s rdf:type kb:USER)
(?s kb:Interest ?i)
regex(?i,'C Language')
]
随之而来的推论是
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:kb="http://protege.stanford.edu/kb#"
xmlns:j.0="http://protege.stanford.edu/kb#LikeC++"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Suresh">
<rdf:type rdf:resource="http://protege.stanford.edu/kb#USER"/>
<kb:Email>suresh_345@yahoo.co.in</kb:Email>
<kb:Fname>Suresh</kb:Fname>
<kb:Interest>Java</kb:Interest>
<kb:Occupation>Agent</kb:Occupation>
<kb:Password>suresh</kb:Password>
<kb:Uname>suresh</kb:Uname>
<rdfs:label>Suresh</rdfs:label>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Raj">
<kb:Occupation>Student</kb:Occupation>
<kb:Interest>C Language</kb:Interest>
<kb:Uname>raj</kb:Uname>
<kb:Password>lkj</kb:Password>
<kb:Name>Raj</kb:Name>
<kb:Email>ra@gmail.com</kb:Email>
</rdf:Description>
<rdf:Description rdf:about="http://protege.stanford.edu/kb#Anvika">
<rdf:type rdf:resource="http://protege.stanford.edu/kb#USER"/>
<kb:Email>anu@gmail.com</kb:Email>
<kb:Fname>Anvika</kb:Fname>
<kb:Interest>C Language</kb:Interest>
<kb:Occupation>Student</kb:Occupation>
<kb:Password>anu</kb:Password>
<kb:Uname>anu</kb:Uname>
<rdfs:label>Anvika</rdfs:label>
<rdf:type rdf:resource="http://protege.stanford.edu/kb#LikeC++"/>
</rdf:Description>
</rdf:RDF>
现在由于线路有
<rdf:type rdf:resource="http://protege.stanford.edu/kb#LikeC++"/>
inference 给用户 Anvika 推荐 LikeC++。但是对于同样对 C 语言感兴趣的用户 Raj 来说也是如此。我知道该行仅导致推断出用户 Anvika。但是这条线是通过 Protege 自动添加的。我的程序不这样做。那么如何通过我的应用程序添加该行。如果这不可能,请告诉我如何更改规则以推断正确的结果。
请帮我。我被这件事震惊了很长时间。