Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top