rdfrowlex

Assigning multiple values to a property


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?


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:

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