为属性分配多个值
我在我的项目中使用 rowlex 。 我的 RDF 文件中有一个分配给个人的属性,它有一个值。 例如,对于个人“学生”,有一个属性“isMemberOf”,其值为类 uri“class00021”。 然后我想向该属性添加第二个值。 例如,“Project”值的 uri 为“proj000052”。
问题出现在这里:添加第二个值后,第一个值被抛出属性“isMemberOf”,甚至抛出其个体(学生),并存储为新个体。
我用于此操作的代码是这样的:
//Add a class to a student
public void Add_Class
(string uri_stu, string uri_class)
{
//Open RDF
RdfDocument rdfDoc = new RdfDocument(@"RDF_Repository\RDF_Student.rdf");
//Find the student
//Student student = new Student(uri_stu, rdfDoc);
Student student = (Student)rdfDoc.GetIndividual(uri_stu);
//Add a class
student.studyMemberOf = new ClassOfCourse(uri_class, rdfDoc);
rdfDoc.ExportToRdfXml(@"RDF_Repository\RDF_Student.rdf");
}
//Add a project to a student
public void Add_Project
(string uri_stu, string uri_proj)
{
//Open RDF
RdfDocument rdfDoc = new RdfDocument(@"RDF_Repository\RDF_Student.rdf");
//Find the student
Student student = (Student)rdfDoc.GetIndividual(uri_stu);
//Add a project
student.studyMemberOf = new Project(uri_proj, rdfDoc);
rdfDoc.ExportToRdfXml(@"RDF_Repository\RDF_Student.rdf");
}
结果 RDF 是这样的:
<?xml version="1.0"?>
<rdf:RDF xmlns:Ontologyowl="http://www.owl-ontologies.com/Ontology1243411901.owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<Ontologyowl:Student rdf:about="stu000012">
<Ontologyowl:studyMemberOf>
<Ontologyowl:Project rdf:about="proj000052"/>
</Ontologyowl:studyMemberOf>
</Ontologyowl:Student>
<Ontologyowl:ClassOfCourse rdf:about="class000021"/>
</rdf:RDF>
... 如果我们继续添加,之前的属性将被丢弃。 那么我该如何克服这个问题呢?
I am using rowlex in my project. I have a property assigned to an individual in my RDF file, which has a value. For example for individual 'Student', there is a property 'isMemberOf', with value of a class uri 'class00021'.
Then I want to add a second value to this property. For instance a 'Project' value with uri 'proj000052'.
The problem appears here: after adding the second value, first value is thrown out of property 'isMemberOf', even out of its individual (student), and is stored as a new individual.
The code I used for this operation is like this:
//Add a class to a student
public void Add_Class
(string uri_stu, string uri_class)
{
//Open RDF
RdfDocument rdfDoc = new RdfDocument(@"RDF_Repository\RDF_Student.rdf");
//Find the student
//Student student = new Student(uri_stu, rdfDoc);
Student student = (Student)rdfDoc.GetIndividual(uri_stu);
//Add a class
student.studyMemberOf = new ClassOfCourse(uri_class, rdfDoc);
rdfDoc.ExportToRdfXml(@"RDF_Repository\RDF_Student.rdf");
}
//Add a project to a student
public void Add_Project
(string uri_stu, string uri_proj)
{
//Open RDF
RdfDocument rdfDoc = new RdfDocument(@"RDF_Repository\RDF_Student.rdf");
//Find the student
Student student = (Student)rdfDoc.GetIndividual(uri_stu);
//Add a project
student.studyMemberOf = new Project(uri_proj, rdfDoc);
rdfDoc.ExportToRdfXml(@"RDF_Repository\RDF_Student.rdf");
}
The resulted RDF is like this:
<?xml version="1.0"?>
<rdf:RDF xmlns:Ontologyowl="http://www.owl-ontologies.com/Ontology1243411901.owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<Ontologyowl:Student rdf:about="stu000012">
<Ontologyowl:studyMemberOf>
<Ontologyowl:Project rdf:about="proj000052"/>
</Ontologyowl:studyMemberOf>
</Ontologyowl:Student>
<Ontologyowl:ClassOfCourse rdf:about="class000021"/>
</rdf:RDF>
... and if we continue adding, the previous property will be thrown out.
So how can I overcome this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于每个本体类,ROWLEX 都会生成两个 .NET 类:“完整”类和“轻量”类。 这两个自动生成的类通过命名约定进行区分。 如果您的 OWL 类被命名为“Student”,那么 Light 类也将被命名为“Student”。 完整的班级被命名为“Student_”。 它们之间完全可以互换,拥有两个的纯粹目的是方便。 完整的类包含您需要的所有可能的方法/属性。 轻量级仅包含最常用的。 满班的问题是他们真的很拥挤。 对于每个 OWL 属性,您将在 .NET 类中获得 10 个(!)属性和方法:
如果您只有 5 个 OWL 属性需要满足,则自动生成的 .NET 完整类将具有 5x10 个方法/属性。 如此大量的成员很容易削弱智能感知的用处。 因此,通常建议使用轻型等级。
在 light 类上,您只实现了非数组属性(除非基数限制明确指示),并且该属性在内部调用替换方法。 在您的情况下,您需要使用完整的课程。
这是获取和使用完整类的方式(我没有验证代码):
For every ontology class, ROWLEX generates two .NET classes a "full" and a "light" one. The two autogenerated classes are differentiated by naming convention. If your OWL class is named "Student" than the light class will be named "Student", too. The full class is named "Student_". They are completely exchangeable with one another, the sheer purpose of having two is convenience. The full class contains every possible methods/properties you need. The light class contains only the most frequently used ones. The problem with full classes that they get really crowded. For every single OWL property you will get 10 (!) properties and methods for in your .NET class:
If you have just 5 OWL properties to cater for, the autogenerated .NET full class will have 5x10 methods/properties. These high number of members easily defeat the usefulness of intellisense. Hence generally the use of light classes are recommended.
On the light class, you have only the non array property implemented (unless cardinality restrictions explicitly direct otherwise) and that property internally calls the replace method. In your case you need to use the full class.
This is how you get and use the full class (I did not verify the code):
我不熟悉 Rowlex,但我猜问题是您如何创建新的
studyMemberOf
谓词(或者看起来不是)。比较:
和:
似乎表明您正在将一个新个体分配给单个谓词,而不是添加具有相同谓词的新语句(这正是您的问题 - 我不确定这个答案有多大帮助) 。
另外,在风格上,您似乎正在合并有关个人和本体的陈述(它们共享相同的名称空间)。 这可能不是您想要的,通常您的学生、班级和项目个人将是另一个命名空间中的 URI(或匿名节点)。 例如:
I'm not familiar with Rowlex, but I would guess the issue is how you're creating your new
studyMemberOf
predicate (or not, as it seems).Comparing:
and:
Would seem to indicate that you're assigning a new individual to a single predicate, rather than adding a new statement with the same predicate (which is exactly your question -- I'm not sure how helpful this answer is).
Also, on a stylistic note, it seems you are merging your statements about individuals and your ontology (they're sharing the same namespace). That is probably not what you want, usually your student, class, and project individuals would be URIs (or anonymous nodes) in another namespace. For example: