为属性分配多个值

发布于 2024-07-26 00:12:02 字数 1851 浏览 5 评论 0原文

我在我的项目中使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江湖正好 2024-08-02 00:12:02

对于每个本体类,ROWLEX 都会生成两个 .NET 类:“完整”类和“轻量”类。 这两个自动生成的类通过命名约定进行区分。 如果您的 OWL 类被命名为“Student”,那么 Light 类也将被命名为“Student”。 完整的班级被命名为“Student_”。 它们之间完全可以互换,拥有两个的纯粹目的是方便。 完整的类包含您需要的所有可能的方法/属性。 轻量级仅包含最常用的。 满班的问题是他们真的很拥挤。 对于每个 OWL 属性,您将在 .NET 类中获得 10 个(!)属性和方法:

  • 添加(类型安全)
  • 添加(非类型安全)
  • 删除(类型安全)
  • 删除(非类型安全)
  • 替换(类型安全)
  • 替换(非类型安全)
  • 非数组属性(类型安全)
  • 非数组属性(非类型安全)
  • 数组属性(类型安全)
  • 数组属性(非类型安全)

如果您只有 5 个 OWL 属性需要满足,则自动生成的 .NET 完整类将具有 5x10 个方法/属性。 如此大量的成员很容易削弱智能感知的用处。 因此,通常建议使用轻型等级。

在 light 类上,您只实现了非数组属性(除非基数限制明确指示),并且该属性在内部调用替换方法。 在您的情况下,您需要使用完整的课程。

这是获取和使用完整类的方式(我没有验证代码):

Student_ student = (Student_)rdfDoc.GetIndividual(uri_stu, Student.Uri, false);
student.AddstudyMemberOf(new Project(uri_proj, rdfDoc));

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:

  • Add (typesafe)
  • Add (not typesafe)
  • Remove (typesafe)
  • Remove (not typesafe)
  • Replace (typesafe)
  • Replace (not typesafe)
  • Non array property (typesafe)
  • Non array property (not typesafe)
  • Array property (typesafe)
  • Array property (not typesafe)

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):

Student_ student = (Student_)rdfDoc.GetIndividual(uri_stu, Student.Uri, false);
student.AddstudyMemberOf(new Project(uri_proj, rdfDoc));
春庭雪 2024-08-02 00:12:02

我不熟悉 Rowlex,但我猜问题是您如何创建新的 studyMemberOf 谓词(或者看起来不是)。

比较:

student.studyMemberOf = new ClassOfCourse(uri_class, rdfDoc);

和:

student.studyMemberOf = new Project(uri_proj, rdfDoc);

似乎表明您正在将一个新个体分配给单个谓词,而不是添加具有相同谓词的新语句(这正是您的问题 - 我不确定这个答案有多大帮助) 。

另外,在风格上,您似乎正在合并有关个人和本体的陈述(它们共享相同的名称空间)。 这可能不是您想要的,通常您的学生、班级和项目个人将是另一个命名空间中的 URI(或匿名节点)。 例如:

<?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:resource="http://students.uri/stu000012">
        <Ontologyowl:studyMemberOf>
            <Ontologyowl:Project rdf:resource="http://projects.uri/proj000052"/>
        </Ontologyowl:studyMemberOf>
    </Ontologyowl:Student>
    <Ontologyowl:ClassOfCourse rdf:resource="http://classes.uri/class000021"/>
</rdf:RDF>

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:

student.studyMemberOf = new ClassOfCourse(uri_class, rdfDoc);

and:

student.studyMemberOf = new Project(uri_proj, rdfDoc);

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:

<?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:resource="http://students.uri/stu000012">
        <Ontologyowl:studyMemberOf>
            <Ontologyowl:Project rdf:resource="http://projects.uri/proj000052"/>
        </Ontologyowl:studyMemberOf>
    </Ontologyowl:Student>
    <Ontologyowl:ClassOfCourse rdf:resource="http://classes.uri/class000021"/>
</rdf:RDF>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文