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

do not treate default_prefix as CURIE prefix for URIs. Fixes #1041 #265

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions linkml_runtime/dumpers/rdflib_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Optional, Any, Dict, Union
from pydantic import BaseModel

import rdflib
from curies import Converter
from rdflib import Graph, URIRef, XSD
from rdflib.term import Node, BNode, Literal
Expand Down
11 changes: 6 additions & 5 deletions linkml_runtime/utils/schemaview.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ class SchemaView(object):

This class utilizes caching for efficient lookup operations.

TODO: decide how to use this in conjunction with the existing schemaloader, which injects
into the schema rather than providing dynamic methods.

See:
- https://github.com/linkml/linkml/issues/59
- https://github.com/linkml/linkml/discussions/144
Expand Down Expand Up @@ -934,15 +931,19 @@ def get_uri(self, element: Union[ElementName, Element], imports=True, expand=Fal
logging.warning(f'from_schema not populated for element {e.name}')
schema = self.schema_map[self.in_schema(e.name)]
pfx = schema.default_prefix
uri = f'{pfx}:{e_name}'
if pfx in self.namespaces():
uri = f'{pfx}:{e_name}'
else:
uri = f'{pfx}{e_name}'
if expand:
return self.expand_curie(uri)
else:
return uri

def expand_curie(self, uri: str) -> str:
"""
Expands a URI or CURIE to a full URI
Expands a URI or CURIE to a full URI.

:param uri:
:return: URI as a string
"""
Expand Down
16 changes: 16 additions & 0 deletions tests/test_issues/input/linkml_issue_1041.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
id: https://w3id.org/linkml/examples/personinfo
name: personinfo
prefixes:
linkml: https://w3id.org/linkml/
imports:
- linkml:types
default_range: string

classes:
Person:
attributes:
id: ## note: default range is string, NOT an identifier
full_name:
aliases:
phone:
age:
30 changes: 30 additions & 0 deletions tests/test_issues/test_linkml_issue_1041.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from unittest import TestCase

from rdflib import RDF, URIRef

from linkml_runtime.dumpers import rdflib_dumper
from linkml_runtime.utils.schemaview import SchemaView

from tests.test_issues.environment import env
from tests.test_issues.models.linkml_issue_1041 import Person


class Issue1041TestCase(TestCase):
"""
https://github.com/linkml/linkml/issues/1041
"""
env = env

def test_issue_default_prefix(self):
view = SchemaView(env.input_path('linkml_issue_1041.yaml'))
uri = view.get_uri(view.get_class("Person"), expand=True)
person_uri = "https://w3id.org/linkml/examples/personinfo/Person"
self.assertEqual(uri, person_uri)
p = Person(id="ORCID:1234", full_name="Clark Kent", age="32", phone="555-555-5555")
g = rdflib_dumper.as_rdf_graph(p, view)
bnodes = g.subjects(RDF.type, URIRef(person_uri))
self.assertEqual(1, len(list(bnodes)))


if __name__ == "__main__":
unittest.main()
Loading