Skip to content

Commit c844c3e

Browse files
authored
Fixes CURIE detection regex based on W3C CURIE Syntax 1.0. (#18)
1 parent beafd04 commit c844c3e

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

rdfpandas/graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def _is_curie(value: object) -> bool:
303303
304304
"""
305305

306-
return re.match('^\w*:\w*$', str(value))
306+
return re.match('^[_A-Za-z][-._A-Za-z0-9]*:.+$', str(value))
307307

308308
def _is_uri(value: object) -> bool:
309309
"""
@@ -321,5 +321,5 @@ def _is_uri(value: object) -> bool:
321321
322322
"""
323323

324-
return re.match('^http[s]?://.*$', str(value))
324+
return re.match('^http[s]?://.+$', str(value))
325325

tests/test_graph.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,31 @@ def test_should_convert_data_frame_to_graph_uriref(self):
198198

199199
self.assertEquals(rdflib.compare.isomorphic(g_expected, g_result), True)
200200

201+
def test_should_convert_data_frame_to_graph_uriref_curie(self):
202+
"""Should create triples based on several compliant CURIES.
203+
"""
204+
205+
ds1 = pd.Series(data=['prefix:suffix'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
206+
ds2 = pd.Series(data=['preffix-._1.:suffix-._1'], index = ['http://github.com/cadmiumkitty/rdfpandas/one'], dtype = np.unicode_)
207+
208+
df = pd.DataFrame({
209+
'http://github.com/cadmiumkitty/rdfpandas/curie1{URIRef}': ds1,
210+
'http://github.com/cadmiumkitty/rdfpandas/curie2{URIRef}': ds2,
211+
})
212+
213+
g_expected = Graph()
214+
215+
g_expected.add((URIRef('http://github.com/cadmiumkitty/rdfpandas/one'),
216+
URIRef('http://github.com/cadmiumkitty/rdfpandas/curie1'),
217+
URIRef('prefix:suffix')))
218+
g_expected.add((URIRef('http://github.com/cadmiumkitty/rdfpandas/one'),
219+
URIRef('http://github.com/cadmiumkitty/rdfpandas/curie2'),
220+
URIRef('preffix-._1.:suffix-._1')))
221+
222+
g_result = rdfpandas.to_graph(df)
223+
224+
self.assertEquals(rdflib.compare.isomorphic(g_expected, g_result), True)
225+
201226
def test_should_convert_data_frame_to_graph_bnode(self):
202227
"""Should create triples based on BNode instance type.
203228
"""

0 commit comments

Comments
 (0)