diff --git a/biolinkml/generators/rdfgen.py b/biolinkml/generators/rdfgen.py index b19e69ce..ec4110f4 100644 --- a/biolinkml/generators/rdfgen.py +++ b/biolinkml/generators/rdfgen.py @@ -5,6 +5,7 @@ """ import os +import urllib.parse as urlparse from typing import Union, TextIO, Optional import click @@ -32,7 +33,12 @@ def _data(self, g: Graph) -> str: def end_schema(self, output: Optional[str] = None, context: str = METAMODEL_CONTEXT_URI, **_) -> None: gen = JSONLDGenerator(self, fmt=JSONLDGenerator.valid_formats[0], emit_metadata=self.emit_metadata, importmap=self.importmap) + # Iterate over permissible text strings making them URI compatible + for e in gen.schema.enums.values(): + for pv in e.permissible_values.values(): + pv.text = urlparse.quote(pv.text) jsonld_str = gen.serialize(context=context) + graph = Graph() graph.parse(data=jsonld_str, format="json-ld", base=self.namespaces._base, prefix=True) if output: diff --git a/tests/test_issues/test_issue_167.py b/tests/test_issues/test_issue_167.py index bb287343..eabc81de 100644 --- a/tests/test_issues/test_issue_167.py +++ b/tests/test_issues/test_issue_167.py @@ -33,12 +33,12 @@ def test_issue_167b_python(self): """ Annotations python example """ env.generate_single_file('issue_167b.py', lambda: PythonGenerator(env.input_path('issue_167b.yaml'), - importmap=env.import_map).serialize(), + importmap=env.import_map, emit_metadata=False).serialize(), comparator=lambda exp, act: compare_python(exp, act, self.env.expected_path('issue_167b.py')), value_is_returned=True) - env.generate_single_file('issue_167b.py', + env.generate_single_file('issue_167b2.py', lambda: PythonGenerator(env.input_path('issue_167b.yaml'), - importmap=env.import_map, mergeimports=False).serialize(), + importmap=env.import_map, mergeimports=False, emit_metadata=False).serialize(), comparator=lambda exp, act: compare_python(exp, act, self.env.expected_path('issue_167b_nomerged.py')), value_is_returned=True) diff --git a/tests/test_issues/test_issue_344.py b/tests/test_issues/test_issue_344.py index a7d60c8d..03570234 100644 --- a/tests/test_issues/test_issue_344.py +++ b/tests/test_issues/test_issue_344.py @@ -7,15 +7,16 @@ from tests.test_issues.environment import env -class Issue167TestCase(TestEnvironmentTestCase): +class Issue344TestCase(TestEnvironmentTestCase): env = env def test_issue_344(self): """ Test to check if prefixes of CURIEs from granular mappings show up in the json-ld context """ x = env.generate_single_file('issue_344_context.json', lambda: ContextGenerator(env.input_path('issue_344.yaml'), - importmap=env.import_map).serialize(), value_is_returned=True) - context = json.load(open(os.path.join(env.outdir, 'issue_344_context.json'))) + importmap=env.import_map, emit_metadata=False).serialize(), value_is_returned=True) + with open(os.path.join(env.outdir, 'issue_344_context.json')) as f: + context = json.load(f) self.assertIn('PCO', context['@context']) self.assertIn('PATO', context['@context']) self.assertIn('GO', context['@context']) diff --git a/tests/test_issues/test_issue_381.py b/tests/test_issues/test_issue_381.py new file mode 100644 index 00000000..170fbbe0 --- /dev/null +++ b/tests/test_issues/test_issue_381.py @@ -0,0 +1,32 @@ +import unittest + +from rdflib import Graph, Namespace + +from biolinkml.generators.jsonldgen import JSONLDGenerator +from biolinkml.generators.rdfgen import RDFGenerator +from biolinkml.meta import META +from tests.utils.test_environment import TestEnvironmentTestCase +from tests.test_issues.environment import env + +NS = Namespace('https://example.org/test/') + +schema = f'''id: {NS} +enums: + test_enum: + permissible_values: + a b: +''' + + +class Issue381TestCase(TestEnvironmentTestCase): + """ Test URL generation w/ non-mangled values """ + env = env + + def test_non_url_pv(self): + g = Graph() + g.parse(data=RDFGenerator(schema).serialize(), format="ttl") + self.assertEqual('https://example.org/test/a%20b', str(g.value(NS.test_enum, META.permissible_values))) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_scripts/output/gengraphviz/meta/alt_description.png b/tests/test_scripts/output/gengraphviz/meta/alt_description.png index 9b06e57e..7d3c4f4a 100644 Binary files a/tests/test_scripts/output/gengraphviz/meta/alt_description.png and b/tests/test_scripts/output/gengraphviz/meta/alt_description.png differ diff --git a/tests/test_scripts/output/gengraphviz/meta1/alt_description.svg b/tests/test_scripts/output/gengraphviz/meta1/alt_description.svg index 23062c3e..d8ce7a88 100644 --- a/tests/test_scripts/output/gengraphviz/meta1/alt_description.svg +++ b/tests/test_scripts/output/gengraphviz/meta1/alt_description.svg @@ -1,13 +1,13 @@ - - + - + alt_description @@ -43,14 +43,14 @@ alt_description_source - -ncname + +string alt_description_text - -string + +string diff --git a/tests/test_scripts/output/gengraphviz/meta1/example.svg b/tests/test_scripts/output/gengraphviz/meta1/example.svg index a9cf0326..9161812c 100644 --- a/tests/test_scripts/output/gengraphviz/meta1/example.svg +++ b/tests/test_scripts/output/gengraphviz/meta1/example.svg @@ -1,7 +1,7 @@ - - -