gtfierro/hod-v1

Support for literals

Closed this issue · 3 comments

This is how we'll store information; not going to be using the "links" anymore

Background

The following building definition:

@prefix brick: <http://buildsys.org/ontologies/Brick#> .
@prefix bf:    <http://buildsys.org/ontologies/BrickFrame#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ns:    <http://google.com#> .

ns:build  rdf:type        brick:Building .
ns:floor  rdf:type        brick:Floor .
ns:room1  rdf:type        brick:Room .
ns:room2  rdf:type        brick:Room .

ns:floor  bf:isLocatedIn  ns:build .
ns:room1  bf:isLocatedIn  ns:floor .
ns:room2  bf:isLocatedIn  ns:floor .

ns:room1  rdfs:label      "Room 1" .
ns:room2  rdfs:label      "Room 2" .

Case 1 - Literals in the Output

Query:

SELECT DISTINCT ?label
WHERE {
    ?room  rdf:type    brick:Room .
    ?room  rdfs:label  ?label .
};

Result using python rdflib:

[
    [
        "Room 2"
    ],
    [
        "Room 1"
    ]
]

Result using HodDB:

{
    "Rows": [
        {
            "?label": {
                "Namespace": "",
                "Value": "\"Room 1\""
            }
        },
        {
            "?label": {
                "Namespace": "",
                "Value": "\"Room 2\""
            }
        }
    ],
    "Links": null,
    "Count": 0
}

Note: The values include escaped double quotes bracketing the correct value.

Case 2 - Literals in the Input

Query:

SELECT DISTINCT ?room
WHERE {
    ?room  rdf:type    brick:Room .
    ?room  rdfs:label  "Room 1" .
};

Result using python rdflib:

[
    [
        "http://google.com#room1"
    ]
]

Result using HodDB: Error parsing: syntax error. Current line 78:64. Recent token '"Room 1"'

I made some initial fixes concluding in d13442f to address this. It passes the two scenarios you've detailed. Haven't gotten a chance to write unit tests around this yet to see if I forgot anything, but at least it doesn't seem to break any existing behavior

Added a couple tests for literals support in queries. Going to mark this closed for now until we run into any issues with the implementation