morph-kgc icon indicating copy to clipboard operation
morph-kgc copied to clipboard

BUG: JsonPath error for accessing nested value with child operator in Mac

Open thomas-stroobants opened this issue 3 years ago • 4 comments

What Happens?

When generating triples for gtfs-rt data, accessing the arrival and departure times gives an error for JSONPath:

ERROR:jsonpath:'NoneType' object has no attribute 'get'

However, the triples are generated fine giving the output that I expected.

To Reproduce

Mapping file:

@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix map: <http://mapping.example.com/> .
@prefix ma: <http://www.w3.org/ns/ma-ont#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix sd: <http://www.w3.org/ns/sparql-service-description#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rev: <http://purl.org/stuff/rev#> .
@prefix v: <http://rdf.data-vocabulary.org/#> .
@prefix schema: <http://schema.org/> .
@prefix gtfs: <http://vocab.gtfs.org/terms#> .
@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix dct: <http://purl.org/dc/terms/> .  
@base <http://example.com> .

<#ArrivalTimeMapping> a rr:TriplesMap;
    rml:logicalSource [
        rml:source "./morph-kgc/nmbs-rt-json-new-adap.json" ;
        rml:iterator "$.entity[*].tripUpdate.stopTimeUpdate[*]" ;
        rml:referenceFormulation ql:JSONPath 
    ];

    rr:subjectMap [
        rr:template "http://example.com/nmbs/stoptimes/{tripId}-{stopId}"  ;
    ];

    rr:predicateObjectMap [
        rr:predicate gtfs:arrivalTime ;
        rr:objectMap [
            rml:reference "arrival.time";
            rr:datatype xsd:time;
        ]
    ].

<#DepartureTimeMapping> a rr:TriplesMap;
    rml:logicalSource [
        rml:source "./morph-kgc/nmbs-rt-json-new-adap.json" ;
        rml:iterator "$.entity[*].tripUpdate.stopTimeUpdate[*]" ;
        rml:referenceFormulation ql:JSONPath 
    ];

    rr:subjectMap [
        rr:template "http://example.com/nmbs/stoptimes/{tripId}-{stopId}"  ;
    ];

    rr:predicateObjectMap [
        rr:predicate gtfs:departureTime ;
        rr:objectMap [
            rml:reference "departure.time";
            rr:datatype xsd:time;
        ]
    ].

Sample data:

{
  "entity": [
    {
      "id": "88____:007::8869054:8814001:52:1028:20231208",
      "tripUpdate": {
        "stopTimeUpdate": [
          {
            "arrival": {
              "delay": 60,
              "time": "07:32:00"
            },
            "departure": {
              "delay": 60,
              "time": "07:37:00"
            },
            "stopId": "8866001",
            "tripId": "88____:007::8869054:8814001:52:1028:20231208",
            "tripStartDate": "20221219",
            "tripStartTime": "07:24:00"
          },
          {
            "arrival": {
              "delay": 0,
              "time": "07:48:00"
            },
            "departure": {
              "delay": 0,
              "time": "07:49:00"
            },
            "stopId": "8866175",
            "tripId": "88____:007::8869054:8814001:52:1028:20231208",
            "tripStartDate": "20221219",
            "tripStartTime": "07:24:00"
          },
          {
            "arrival": {
              "delay": 240,
              "time": "08:20:00"
            },
            "departure": {
              "delay": 240,
              "time": "08:20:00"
            },
            "stopId": "8865227",
            "tripId": "88____:007::8869054:8814001:52:1028:20231208",
            "tripStartDate": "20221219",
            "tripStartTime": "07:24:00"
          },
          {
            "arrival": {
              "delay": 180,
              "time": "08:34:00"
            },
            "departure": {
              "delay": 120,
              "time": "08:34:00"
            },
            "stopId": "8864006",
            "tripId": "88____:007::8869054:8814001:52:1028:20231208",
            "tripStartDate": "20221219",
            "tripStartTime": "07:24:00"
          },
          {
            "arrival": {
              "delay": 0,
              "time": "08:38:00"
            },
            "departure": {
              "delay": 120,
              "time": "08:41:00"
            },
            "stopId": "8864345",
            "tripId": "88____:007::8869054:8814001:52:1028:20231208",
            "tripStartDate": "20221219",
            "tripStartTime": "07:24:00"
          },
          {
            "arrival": {
              "delay": 120,
              "time": "08:43:00"
            },
            "departure": {
              "delay": 120,
              "time": "08:43:00"
            },
            "stopId": "8864352",
            "tripId": "88____:007::8869054:8814001:52:1028:20231208",
            "tripStartDate": "20221219",
            "tripStartTime": "07:24:00"
          }
        ]
      }
    }
  ]
}

Environment (please complete the following information):

  • OS: MacOS 12.6
  • Python version: 3.9.5
  • Morph-KGC version: 2.3.1

thomas-stroobants avatar Dec 20 '22 11:12 thomas-stroobants

Hi @thomas-stroobants ,

This is working fine for me on Linux. Could you try with version 2.2.0?

arenas-guerrero-julian avatar Dec 22 '22 16:12 arenas-guerrero-julian

Hi @ArenasGuerreroJulian,

Thank you for replying, running the code on WSL:Ubuntu with version 2.3.1 gives me no issue, on MacOS it did. Using version 2.2.0 on MacOS gives no error messages.

thomas-stroobants avatar Jan 03 '23 10:01 thomas-stroobants

I have done a small change to fix this.

If possible, @thomas-stroobants, verify this by installing from source in Mac:

pip install git+https://github.com/oeg-upm/morph-kgc.git

And executing with your mappings and data.

arenas-guerrero-julian avatar Jan 04 '23 11:01 arenas-guerrero-julian

@ArenasGuerreroJulian, installing the new version unfortunately did not solve the error messages.

thomas-stroobants avatar Jan 05 '23 12:01 thomas-stroobants

This is related to the broader issue #269.

arenas-guerrero-julian avatar Aug 22 '24 19:08 arenas-guerrero-julian