0

For a school project, we have to use RDF and OWL to create a vacancy/applicant service. We are writing this service with Spring and Apache Jena. This service will contain persons that have certain skills and vacancies of companies that require some skills. We've created the ontologies, but we can't find out how to create a skill and link it to a person.

First we tried to make an hasSkill objectproperty directly to a foaf:person with the following code:

<owl:ObjectProperty rdf:about="foaf#hasSkill">
    <owl:domain owl:class="foaf#person" />
<owl:range owl:class="#Skill" />
</owl:ObjectProperty>

We tried inserting these skills using SparQL, but we couldn't find out how to link the created skill to an existing user. Another method we tried is accessing the property by code.

Resource user = userRepository.getUserResource(userID);
Property skill = model.createProperty("Skill");

Where the first line gets the user's resource by querying it with SparQL.

The code defining the Skill-ontology:

<owl:Class owl:name="Skill">
<owl:Annotation>
    <owl:Label>Skill</owl:Label>
</owl:Annotation>
</owl:Class>

<owl:ObjectProperty rdf:about="http://localhost:8080/ontologies/Skill#SkillName">
  <owl:domain owl:class="Skill" />
  <owl:range owl:class="rdfs#literal"/>
</owl:ObjectProperty>

<owl:ObjectProperty rdf:about="http://localhost:8080/ontologies/Skill#CompetencyLevel">
  <owl:domain owl:class="Skill" />
  <owl:range owl:class="rdfs#literal" />
</owl:ObjectProperty>

The code defining our applicant ontology:

<owl:Class owl:name="Applicant">
    <owl:Annotation>
      <owl:Label>Applicant</owl:Label>
</owl:Annotation>
</owl:Class>

<owl:ObjectProperty rdf:about="http://localhost:8080/ontologies/Applicant#Person">
    <owl:domain owl:class="Applicant" />
  <owl:range owl:class="foaf#person" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:about="http://localhost:8080/ontologies/Degree#StudyField">
    <owl:domain owl:class="Applicant" />
    <owl:range owl:class="#Skill" />
</owl:ObjectProperty>

What we want to do is that an existing user can add skills to their profile. These skills then can be used to match vacancies to the applicant.

After the suggestion of AKSW, I tried to use the Resource class of Jena:

Property name = ResourceFactory.createProperty("", ns + "Skill#SkillName");
Property competencyLvl = ResourceFactory.createProperty("", ns + "Skill#CompetencyLevel");
Resource r = model.getModel().createResource("Skill")
            .addProperty(name, skillDetail.getSkillName())
            .addProperty(competencyLvl, skillDetail.getCompetencyLevel());

model.writeChanges();

The namespace (ns) is equal to "http://localhost:8080/ontologies/" But this gives me the error that a required component is missing in the scheme.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • The class [`Resource`](https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Resource.html) provides all the methods you need, e.g. `addProperty`, `addLiteral` etc. - Javadoc or the Apache Jena doc is always your friend – UninformedUser Jan 02 '19 at 14:28
  • @AKSW thanks for the response! I tried your suggestion, but the **addProperty** requires a property instance, which I created with the **resourceFactory** with namespace "" and for example **localName** _ns + "Skill#SkillName_. But i get an error that a required component is missing in the scheme – Bram Kelchtermans Jan 02 '19 at 15:49
  • Can you please add the code that doesn't work to the question? It's easier for me to reproduce resp. find the mistake. Note, it has to be a proper URL, please also show the String you're passing to the resource factory. – UninformedUser Jan 02 '19 at 16:01
  • @AKSW Done, thanks for your time! – Bram Kelchtermans Jan 02 '19 at 16:04
  • Ok, so why `ResourceFactory.createProperty("", ns + "Skill#SkillName");` ? The frist argument is supposed to be the namespace, you just pass `""` . Look at the Javadoc again: `createProperty(String namespace, String localName)` - so, shouldn't it `createProperty(ns, "Skill#SkillName")` ? – UninformedUser Jan 02 '19 at 16:37
  • It still won't work. I tried what you said, but got the same error. Could be that it has something to do with the ontology definition itself? Right now i define it by a rdf:about, doesn't it have to be owl:name? – Bram Kelchtermans Jan 02 '19 at 16:43
  • that doesn't matter. what is `ns` in your case? it has to be the beginning of a URI, e.g. `http://` - your could also simple pass the whole URI, e.g. `getProperty("http://example.org/Skill#SkillName")` – UninformedUser Jan 02 '19 at 18:44
  • @AKSW I've added it to the post. In my case ns is http://localhost:8080/ontologies/ – Bram Kelchtermans Jan 02 '19 at 19:09
  • as I said before, the first argument is supposed to be the namespace: `createProperty(String namespace, String localName) ` - I don't understand why you pass an empty string `""` as first argument instead of just `ns`? Why not `createProperty(ns, "Skill#SkillName")` ? – UninformedUser Jan 03 '19 at 06:31
  • Thank you all for your feedback. The suggestion of @AKSW worked! – Bram Kelchtermans Jan 03 '19 at 18:54

0 Answers0