简体   繁体   中英

Add List of Strings to an ontology using JENA in JAVA

I am currently creating an ontology using Jena and JAVA. Adding Strings to an ontology is straight forward but I ran into problems adding a list of Strings... As for example let's assume the following data:

Eg: A task has:

  • label (String)
  • URI (String)
  • Description (String)
  • Activities (List of Strings)

The only way I could successfully enter the list of activities, is by transforming the List of Strings to a String with the following code:

private static String convertListToString(List<String> list) {
    String listString = "";
    for (String line : list) {
        listString += line + ".";
    }
    return listString;
}

This means in other words, I transformed the following list of activities:

  • Decide on the change process; describe and declare it in the project management plan
  • Record amendment requests in the change status list and update entries
  • Analyze amendment requests and approve/reject them

to the following String: "Decide on the change process; describe and declare it in the project management plan. Record amendment requests in the change status list and update entries. Analyze amendment requests and approve/reject them."

Now, I want to get rid of this dummy approach and would like to add the list of activities as it is to the ontology but unfortunately I could not find out how to handle Lists/Arrays/Maps, ... in JENA. I would be happy for any help.

Thank you.

I believe your question is due to a misunderstanding of how ontologies handle lists, respectively, how one-to-many or many-to-many relations are modelled with ontologies.

If the list contains multiple entries then those are likely separate instances of a triplet in your ontology. In your case, using highly simplified pseudocode:

Task hasActivity Activity

This is the model (well part of) your ontology. Instantiate the triplet once per entry in your list by, for example, looping over your list.

When a user then queries the ontology for:

Task hasActivity ?activity

A list of all activities for a given task will be returned.

A friend just told me to simply loop over the the List of Strings and within the loop add a property equally to a String.

Eg

for (String activity : activities) {
   addProperty(activity)
}

This approach works fine, but it does not look as a List for me in the ontology file:

<rdf:Description rdf:about="http://www.list.lu/ontologies/2015/hermes/1.0.0#Conduire et contrôler le projet">
    <Description xml:lang="fr">L’avancement du projet est vérifié en permanence et la planification est actualisée.</Description>
    <Activity xml:lang="fr">Coordonner les interdépendances entre les mandats</Activity>
    <Activity xml:lang="fr">Analyser les écarts par rapport à la planification et initier les mesures qui s’imposent</Activity>
    <Activity xml:lang="fr">Exécuter la réunion de lancement avec les parties concernées et concevoir la culture du projet</Activity>
    <Activity xml:lang="fr">Actualiser en permanence le plan de gestion du projet</Activity>
    <Activity xml:lang="fr">Etablir les mandats de travail et assurer une compréhension commune en ce qui concerne la démarche et les résultats</Activity>
    <Activity xml:lang="fr">Déterminer les conditions-cadres et les prescriptions pour le reporting</Activity>
    <Label xml:lang="fr">aufgabe_projekt_fuehren_und_kontrollieren</Label>
    <Activity xml:lang="fr">Diriger les collaborateurs du projet et assurer l’orientation vers les objectifs</Activity>
    <Activity xml:lang="fr">Coordonner en permanence avec le mandant le déroulement du projet et les importantes constatations faites</Activity>
</rdf:Description>

So if anyone has another approach, I am glad to hear it.

Thanks again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM