diff --git a/rdfpandas/graph.py b/rdfpandas/graph.py index ec81476..564fc44 100644 --- a/rdfpandas/graph.py +++ b/rdfpandas/graph.py @@ -303,7 +303,7 @@ def _is_curie(value: object) -> bool: """ - return re.match('^\w*:\w*$', str(value)) + return re.match('^[_A-Za-z][-._A-Za-z0-9]*:.+$', str(value)) def _is_uri(value: object) -> bool: """ @@ -321,5 +321,5 @@ def _is_uri(value: object) -> bool: """ - return re.match('^http[s]?://.*$', str(value)) + return re.match('^http[s]?://.+$', str(value)) diff --git a/tests/test_graph.py b/tests/test_graph.py index 2dc3066..e2935a5 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -198,6 +198,31 @@ def test_should_convert_data_frame_to_graph_uriref(self): self.assertEquals(rdflib.compare.isomorphic(g_expected, g_result), True) + def test_should_convert_data_frame_to_graph_uriref_curie(self): + """Should create triples based on several compliant CURIES. + """ + + ds1 = pd.Series(data=['prefix:suffix'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_) + ds2 = pd.Series(data=['preffix-._1.:suffix-._1'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_) + + df = pd.DataFrame({ + 'http://github.com/cadmiumkitty/rdfpandas/curie1{URIRef}': ds1, + 'http://github.com/cadmiumkitty/rdfpandas/curie2{URIRef}': ds2, + }) + + g_expected = Graph() + + g_expected.add((URIRef('http://github.com/cadmiumkitty/rdfpandas/one'), + URIRef('http://github.com/cadmiumkitty/rdfpandas/curie1'), + URIRef('prefix:suffix'))) + g_expected.add((URIRef('http://github.com/cadmiumkitty/rdfpandas/one'), + URIRef('http://github.com/cadmiumkitty/rdfpandas/curie2'), + URIRef('preffix-._1.:suffix-._1'))) + + g_result = rdfpandas.to_graph(df) + + self.assertEquals(rdflib.compare.isomorphic(g_expected, g_result), True) + def test_should_convert_data_frame_to_graph_bnode(self): """Should create triples based on BNode instance type. """