Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use types from the triplestore in predicate objects in ontologies #767

Merged
merged 5 commits into from Mar 10, 2018

Conversation

benjamingeer
Copy link

@benjamingeer benjamingeer commented Mar 8, 2018

The case class PredicateInfoV2 stores the objects of predicates of ontology entities. Currently, PredicateInfoV2 stores all its objects as strings. When ontology information is converted from one schema to another, objects that are actually IRIs have to be converted. Since PredicateInfoV2 doesn't know the types of its objects, something else has to keep track of that. So there are hard-coded sets of predicates that are known to have IRIs as objects, but this is cumbersome. It also means that to convert an IRI, PredicateInfoV2 needs to convert a string to a SmartIri and back again.

This PR takes advantage of the type information that comes with SparqlExtendedConstructResponse to enable PredicateInfoV2 to store store IRIs as SmartIri objects instead of strings.

  • Add a trait OntologyLiteralV2, which is like LiteralV2 but has just the implementations needed by PredicateInfoV2. (OntologyLiteralV2 shares some of its implementations with LiteralV2.)
  • Refactor PredicateInfoV2 to use OntologyLiteralV2.
  • Use a Seq instead of a Set for the objects in PredicateInfoV2, so a Seq[StringLiteralV2] can be accepted as a Seq[OntologyLiteralV2] (this doesn't work with Set, because Set is not covariant in its type parameter).
  • Fix bug: when API v2 served knora-api (default schema), salsah-gui:guiElement and salsah-gui:guiAttribute were not shown in properties in that ontology.
  • Fix bug: salsah-gui:guiOrder was not accepted when creating a property via API v2.

As a result, PredicateInfoV2.toOntologySchema becomes nice and simple:

def toOntologySchema(targetSchema: OntologySchema): PredicateInfoV2 = {
    copy(
        predicateIri = predicateIri.toOntologySchema(targetSchema),
        objects = objects.map {
            case smartIriLiteral: SmartIriLiteralV2 => smartIriLiteral.toOntologySchema(targetSchema)
            case other => other
        }
    )
}

Resolves #738.

@benjamingeer benjamingeer added bug something isn't working enhancement improve existing code or new feature in-progress labels Mar 8, 2018
@benjamingeer benjamingeer added this to the v1.3.0 milestone Mar 8, 2018
@benjamingeer benjamingeer mentioned this pull request Mar 8, 2018
Copy link
Collaborator

@subotic subotic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks :-)

@benjamingeer
Copy link
Author

Thanks for the review!

@subotic
Copy link
Collaborator

subotic commented Mar 10, 2018

you shouldn't work on a Saturday ;-)

@benjamingeer
Copy link
Author

Neither should you. :)

@benjamingeer benjamingeer merged commit 6a34e26 into develop Mar 10, 2018
@benjamingeer benjamingeer deleted the wip/typed-literals-in-ontology-info branch March 10, 2018 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something isn't working enhancement improve existing code or new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants