OntoUML / ontouml-js

Javascript library for manipulating OntoUML models.
Apache License 2.0
11 stars 8 forks source link

[feature] add custom labels #33

Closed LucasBassetti closed 4 years ago

LucasBassetti commented 4 years ago

Introduction

This PR adds the option to add custom labels. (#29)

How to use

You can use id or name for create custom labels. Like so:

customLabels: {
  JoK2ZeaGAqACBxS5: 'OWLPerson',
  Organization: 'OWLOrganization',
}

Output

:OWLPerson rdf:type owl:Class
:OWLOrganization rdf:type owl:Class
tgoprince commented 4 years ago

@LucasBassetti the transformation is keeping the original labels even when we add new ones.

For instance, in the example:

{
        name: 'alpinebitsCustomLabel.ttl',
        model: alpinebits,
        options: {
          format: 'Turtle',
          baseIRI: 'https://alpinebits.org',
          createInverses: true,
          customElementMapping: {
            JoK2ZeaGAqACBxS5: { uri: 'OWLPerson', label: { pt: 'Pessoa' } },
            Organization: { uri: 'OWLOrganization' },
            'Event Plan': { uri: 'OWLEventPlan' },
            '3x40WRaGAqCsIB4X': { uri: 'hasTrail', label: { en: 'hasLabel' } },
          },
        },
      }

We get:

:OWLPerson rdf:type owl:Class, owl:NamedIndividual;
    rdfs:label "Person".

:OWLPerson rdfs:subClassOf :Agent, gufo:FunctionalComplex;
    rdf:type gufo:Kind;
    rdfs:label "Pessoa"@pt.

I think this can be confusing to our final users, so I propose we do one of the following:

  1. Add a parameter to inform the transformation to keep or discard original labels
  2. Always discard original labels when new ones are provided

What do you think?

tgoprince commented 4 years ago

If we choose to discard the original labels, we could add the following code fragment to the transformAnnotations function in the annotations_function.ts file:

if (Object.keys(customLabel).length > 0) {
    const elementType =
      typeof element.type === 'string' ? element.type : 'Element';

    let description;

    if (element.name)
      description = elementType +  ' named "' + element.name + '" in the origin conceptual model.';
    else 
      description = elementType + ' unnamed in the origin conceptual model.';

    quads.push( quad(namedNode(uri), namedNode('rdfs:comment'), literal(description)) );
}
LucasBassetti commented 4 years ago

@tgoprince I updated to have a default label. Example

customElementMapping: {
  hF1rKw6GAqACBCXn: {
    uri: 'mediation',
    label: { default: 'OWLMediation' },
  }
}