Skip to content

Commit e5e4d6e

Browse files
committed
remove numarray processing to limit scope
1 parent cde8ca7 commit e5e4d6e

File tree

7 files changed

+7
-72
lines changed

7 files changed

+7
-72
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ _:2432178001088 rdf:_2 3.
2828

2929
## Why?
3030

31-
Motivation: This was developed as part of [BIM2RDF](https://github.com/PNNL/BIM2RDF) where the main implementation language is Python and the data sizes from [Speckle](https://www.speckle.systems/) are not small.
31+
Motivation: This was developed as part of [BIM2RDF](https://github.com/PNNL/BIM2RDF)
32+
where the main implementation language is Python
33+
and the data sizes from [Speckle](https://www.speckle.systems/) are not small.
3234

3335
* [Prior implementation](https://github.com/AtomGraph/JSON2RDF) is in java.
3436
* Don't want to use [JSON-LD](https://json-ld.org/playground/)
@@ -52,14 +54,11 @@ This is close to the 'spirit' of the semantic web.
5254
However, this makes the conversion non-deterministic.
5355
Reprecussions must be handled by the user.
5456

55-
TODO: list vs arrays.
5657

5758
## Features
5859

5960
Optional:
60-
* **'meta triples'** as RDF-star: `<<{data triple}>> {meta} <<{meta triple}>>`
61-
* **Numerical Arrays**: Numerical lists can be represented as numpy-encoded strings.
62-
(This was motivated by the storage of geometry data from 3D design programs).
61+
**'meta triples'**: as RDF-star: `<<{data triple}>> {meta} <<{meta triple}>>`
6362

6463

6564
## Development Philosophy

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ dependencies = [
1414
]
1515
[project.optional-dependencies]
1616
cli = ["fire"]
17-
numarray = ['numpy']
1817
[dependency-groups]
1918
dev = [
2019
'ipython', 'ipdb',
@@ -30,7 +29,6 @@ Repository = "https://github.com/pnnl/json2rdf.git"
3029
[project.scripts]
3130
json2rdf = "json2rdf:cli"
3231

33-
3432
[build-system]
3533
# > uv build
3634
# > uvx hatchling version major

src/json2rdf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = "66" # shoud equal `git rev-list --count master`
1+
__version__ = "67" # shoud equal `git rev-list --count master`
22
# can roll back to 0 if errors
33
from .json2rdf import json2rdf, j2r

src/json2rdf/cli.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ def _(
99
# id interpretation
1010
subject_id_keys = args['subject_id_keys'] .default,
1111
object_id_keys = args['object_id_keys'] .default,
12-
# array
13-
array_keys = args['array_keys'] .default,
1412
# uri construction
1513
id_prefix = args['id_prefix'] .default,
1614
key_prefix = args['key_prefix'] .default,
@@ -26,7 +24,6 @@ def _(
2624
sort=sort,
2725
subject_id_keys=subject_id_keys,
2826
object_id_keys=object_id_keys,
29-
array_keys=array_keys,
3027
id_prefix=id_prefix,
3128
key_prefix=key_prefix,
3229
meta_prefix=meta_prefix,)

src/json2rdf/json2rdf.py

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,66 +9,16 @@ def classes():
99
# too lazy to convert them to be able to be instantiated.
1010
class Termination:
1111
""" 'pre'-processing """
12-
class NumList(tuple):
13-
def __str__(self, ):
14-
return self.data_encode(self)
15-
keys = frozenset() #{'array', }
16-
17-
@staticmethod
18-
def data_encode(d: list) -> str:
19-
from numpy import savez_compressed as save, array
20-
#from numpy import save
21-
_ = d
22-
_ = array(d, dtype='float16')
23-
from io import BytesIO
24-
def sv(d):
25-
_ = BytesIO()
26-
#save(_, d)
27-
save(_, array=d)
28-
return _
29-
_ = sv(_)
30-
_.seek(0)
31-
_ = _.read()
32-
from base64 import b64encode
33-
_ = b64encode(_)
34-
_ = _.decode()
35-
return _
36-
@staticmethod
37-
def data_decode(d: str) -> 'array':
38-
_ = d
39-
from base64 import b64decode
40-
_ = b64decode(_,)
41-
from numpy import load
42-
from io import BytesIO
43-
_ = BytesIO(_)
44-
_ = load(_)
45-
_ = _['array']
46-
return _
47-
48-
@staticmethod
49-
def allnum(it):
50-
# dont think json has complex, so doesn't matter
51-
return all(isinstance(i, (float, int, complex) ) for i in it)
52-
@staticmethod
53-
def interpret(it):# TODO: could interpret a list of whatever if needed
54-
raise NotImplementedError
55-
5612
terminals = {
5713
int, float,
5814
str,
5915
bool,
6016
type(None), # weird
6117
# does json have datetime?
62-
NumList, # don't traverse these if array
6318
}
6419
terminals = tuple(terminals)
6520
@classmethod
6621
def visit(cls, p, k, v):
67-
if k in cls.NumList.keys:
68-
# permissively create. don't insist on below conditions.
69-
if isinstance(v, list):
70-
if cls.NumList.allnum(v):
71-
return k, cls.NumList(v)
7222
return True
7323

7424
@classmethod
@@ -301,8 +251,6 @@ def triple(cls, s, p, o):
301251
o = '"'+o+'"'
302252
elif isinstance(o, (bool, NoneType)): # https://github.com/w3c/json-ld-syntax/issues/258
303253
o = m[o]
304-
elif isinstance(o, Termination.NumList):
305-
o = '"'+str(o)+'"'
306254
elif isinstance(o, Identification.ID):
307255
if type(o) is Identification.ID:
308256
o = f'{cls.list.id_prefix}:{o}'
@@ -363,8 +311,6 @@ def json2rdf(
363311
# id interpretation
364312
subject_id_keys = defaults.Identification.subject_keys,
365313
object_id_keys = defaults.Identification.object_keys,
366-
# array
367-
array_keys = {},#Termination.NumList.keys,
368314
# # uri construction
369315
id_prefix = (defaults.RDFing.list.id_prefix,
370316
defaults.RDFing.list.id_uri),
@@ -396,8 +342,6 @@ def json2rdf(
396342
f.Identification.subject_keys = [k for k in subject_id_keys if k in frozenset(subject_id_keys)]
397343
f.Identification.object_keys = frozenset(object_id_keys)
398344

399-
f.Termination.NumList.keys = frozenset(array_keys)
400-
401345
f.RDFing.list.id_prefix, f.RDFing.list.id_uri = id_prefix
402346
f.RDFing.list.key_prefix, f.RDFing.list.key_uri = key_prefix
403347
f.RDFing.list.meta_prefix, f.RDFing.list.meta_uri = meta_prefix

test/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ def check_fn(obtained_fn, expected_fn):
3636
if not is_eq(o, e): raise AssertionError
3737
file_regression.check(r, check_fn=check_fn, extension='.ttl')
3838

39+
# json2rdf -i large-file.json -o data.ttl

uv.lock

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)