SDM-TIB / SDM-RDFizer

An Efficient RML-Compliant Engine for Knowledge Graph Construction
https://doi.org/10.5281/zenodo.3872103
Apache License 2.0
107 stars 25 forks source link

SDM-RDFizer crashes on read JSON file #101

Closed ItaloLopes closed 1 year ago

ItaloLopes commented 1 year ago

Describe the bug SDM_RDFizer crashes when I try to map a JSON file.

Crash log:

Semantifying er-experiment-D1...
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniforge/base/envs/dice/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/homebrew/Caskroom/miniforge/base/envs/dice/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/dice/lib/python3.9/site-packages/rdfizer/__main__.py", line 49, in <module>
    main()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/dice/lib/python3.9/site-packages/rdfizer/__main__.py", line 45, in main
    semantify(config_path)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/dice/lib/python3.9/site-packages/rdfizer/__init__.py", line 4633, in semantify
    data = json.load(source)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/dice/lib/python3.9/json/__init__.py", line 293, in load
    return loads(fp.read(),
AttributeError: 'str' object has no attribute 'read'

On lines 4633 and 4676 from semantify.py, the json.load() gets a string instead of a file object. Changing this solved the problem here.

RDFizer config file:

[default]
main_directory: /path/to/data

[datasets]
number_of_datasets: 2
output_folder: ${default:main_directory}/graph
all_in_one_file: yes
remove_duplicate: yes
enrichment: no
ordered: yes
large_file: yes
name: experiment
output_format: n-triples

[dataset1]
name: experiment-D1
mapping: ${default:main_directory}/mapping_one.ttl

[dataset2]
name: experiment-D2
mapping: ${default:main_directory}/mapping_two.ttl

Mappings:

@prefix rr: <http://www.w3.org/ns/r2rml#>.
@prefix rml: <http://semweb.mmlab.be/ns/rml#>.
@prefix ex: <http://example.com/ns#>.
@prefix ql: <http://semweb.mmlab.be/ns/ql#>.
@prefix transit: <http://vocab.org/transit/terms/>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix experiment: <http://www.experiment.com/>.
@base <http://example.com/ns#>.

<#OneMapping> a rr:TriplesMap;
    rml:logicalSource [
        rml:source "path/to/data/input/one.json";
        rml:referenceFormulation ql:JSONPath;
    ];

    rr:subjectMap [
        rr:template "http://www.experiment.com/person/{id}";
        rr:class experiment:Person
    ];

    rr:predicateObjectMap [
        rr:predicate experiment:region;
        rr:objectMap [
            rml:reference "region"
        ]
    ];

    rr:predicateObjectMap [
        rr:predicate experiment:gender;
        rr:objectMap [
            rml:reference "gender"
        ]
    ].
@prefix rr: <http://www.w3.org/ns/r2rml#>.
@prefix rml: <http://semweb.mmlab.be/ns/rml#>.
@prefix ex: <http://example.com/ns#>.
@prefix ql: <http://semweb.mmlab.be/ns/ql#>.
@prefix transit: <http://vocab.org/transit/terms/>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix experiment: <http://www.experiment.com/>.
@base <http://example.com/ns#>.

<#TuxedoMapping> a rr:TriplesMap;
    rml:logicalSource [
        rml:source "path/to/data/input/two.json";
        rml:referenceFormulation ql:JSONPath;
        rml:iterator "$"
    ];

    rr:subjectMap [
        rr:template "http://www.experiment.com/organization/{id}";
        rr:class experiment:Organization
    ];

    rr:predicateObjectMap [
        rr:predicate experiment:placeId;
        rr:objectMap [
            rml:reference "placeId"
        ]
    ];

    rr:predicateObjectMap [
        rr:predicate experiment:people;
        rr:objectMap [
            rml:reference "people.id"
        ]
    ].

To Reproduce Steps to reproduce the behavior (and resources):

  1. Run Mapping for JSON

Expected behavior Successfully semantified the datasets

Desktop (please complete the following information):

eiglesias34 commented 1 year ago

Hello @ItaloLopes,

First of all, thank you for using the SDM-RDFizer. I'm sorry for the late response. I found the issue you mentioned and updated the code. I tested it out, and everything worked. I hope this helps you solve your problem.

Thank you again, Enrique

eiglesias34 commented 1 year ago

Hello @ItaloLopes,

Given the inactivity of this issue, I am going to close it. In case there are any more problems the issue can be reopened.

SIncerely, Enrique Iglesias