示例#1
0
 def test_plus_directed_path_query(self):
     woql_object = WOQLQuery().path("v:X", "<hop+", "v:Y", "v:Path")
     json_object = {
         "@type": "Path",
         "subject": {
             "@type": "NodeValue",
             "variable": "X",
         },
         "pattern": {
             "@type": "PathPlus",
             "plus": {
                 "@type": "InversePathPredicate",
                 "predicate": "hop",
             },
         },
         "object": {
             "@type": "Value",
             "variable": "Y",
         },
         "path": {
             "@type": "Value",
             "variable": "Path",
         },
     }
     assert woql_object.to_dict() == json_object
 def test_woql_pad_method(self):
     woql_object = WOQLQuery().pad("abc", "#", 8, "v:output")
     json_obj = {
         "@type": "woql:Pad",
         "woql:pad_string": {
             "@type": "woql:Datatype",
             "woql:datatype": {
                 "@type": "xsd:string",
                 "@value": "abc"
             },
         },
         "woql:pad_char": {
             "@type": "woql:Datatype",
             "woql:datatype": {
                 "@type": "xsd:string",
                 "@value": "#"
             },
         },
         "woql:pad_times": {
             "@type": "woql:Datatype",
             "woql:datatype": {
                 "@type": "xsd:integer",
                 "@value": 8
             },
         },
         "woql:pad_result": {
             "@type": "woql:Variable",
             "woql:variable_name": {
                 "@value": "output",
                 "@type": "xsd:string"
             },
         },
     }
     assert woql_object.to_dict() == json_obj
    def test_woql_as_method(self):
        woql_object = WOQLQuery().woql_as("Source", "Target")
        woql_object2 = (WOQLQuery().woql_as("Source", "Target").woql_as(
            "Source2", "Target2"))
        json_obj2 = [
            {
                "@type": "woql:NamedAsVar",
                "woql:identifier": {
                    "@type": "xsd:string",
                    "@value": "Source"
                },
                "woql:variable_name": {
                    "@type": "xsd:string",
                    "@value": "Target"
                },
            },
            {
                "@type": "woql:NamedAsVar",
                "woql:identifier": {
                    "@type": "xsd:string",
                    "@value": "Source2"
                },
                "woql:variable_name": {
                    "@type": "xsd:string",
                    "@value": "Target2"
                },
            },
        ]

        assert woql_object.to_dict() == [json_obj2[0]]
        assert woql_object2.to_dict() == json_obj2
示例#4
0
 def test_remote_method(self):
     woql_object = WOQLQuery().remote({"url": "http://url"})
     json_obj = {
         "@type": "woql:RemoteResource",
         "woql:remote_uri": {"@type": "xsd:anyURI", "@value": {"url": "http://url"}},
     }
     assert woql_object.to_dict() == json_obj
 def test_re_method(self):
     woql_object = WOQLQuery().re("!\\w+(.*)test$", "v:string",
                                  "v:formated")
     json_obj = {
         "@type": "woql:Regexp",
         "woql:pattern": {
             "@type": "woql:Datatype",
             "woql:datatype": {
                 "@type": "xsd:string",
                 "@value": "!\\w+(.*)test$"
             },
         },
         "woql:regexp_list": {
             "@type": "woql:Variable",
             "woql:variable_name": {
                 "@type": "xsd:string",
                 "@value": "formated"
             },
         },
         "woql:regexp_string": {
             "@type": "woql:Variable",
             "woql:variable_name": {
                 "@type": "xsd:string",
                 "@value": "string"
             },
         },
     }
     assert woql_object.to_dict() == json_obj
示例#6
0
 def test_comment_method(self):
     woql_object = WOQLQuery().comment("my comment")
     json_obj = {
         "@type": "woql:Comment",
         "woql:comment": {"@type": "xsd:string", "@value": "my comment"},
     }
     assert woql_object.to_dict() == json_obj
 def test_typecast_method(self):
     woql_object = WOQLQuery().typecast("v:Duration", "xsd:integer",
                                        "v:Duration_Cast")
     json_obj = {
         "@type": "woql:Typecast",
         "woql:typecast_value": {
             "@type": "woql:Variable",
             "woql:variable_name": {
                 "@value": "Duration",
                 "@type": "xsd:string"
             },
         },
         "woql:typecast_type": {
             "@type": "woql:Node",
             "woql:node": "xsd:integer"
         },
         "woql:typecast_result": {
             "@type": "woql:Variable",
             "woql:variable_name": {
                 "@value": "Duration_Cast",
                 "@type": "xsd:string",
             },
         },
     }
     assert woql_object.to_dict() == json_obj
def test_happy_carzy_path(docker_url):
    # create client
    client = WOQLClient(docker_url)
    assert not client._connected
    # test connect
    client.connect()
    assert client._connected
    # test create db
    client.create_database("test happy path")
    init_commit = client._get_current_commit()
    assert client.db == "test happy path"
    assert "test happy path" in client.list_databases()
    # assert client._context.get("doc") == "foo://"
    assert len(client.get_commit_history()) == 1
    # test adding something
    client.query(WOQLQuery().add_quad("a", "rdf:type", "sys:Class", "schema"))
    first_commit = client._get_current_commit()
    assert first_commit != init_commit
    assert len(client.get_commit_history()) == 1
    client.query(WOQLQuery().add_quad("b", "rdf:type", "sys:Class", "schema"))
    commit_history = client.get_commit_history()
    assert client._get_target_commit(1) == first_commit
    assert len(client.get_commit_history()) == 2
    # test reset
    client.reset(commit_history[-1]["commit"])
    assert client._get_current_commit() == first_commit
    client.create_branch("New Branch")
    client.rebase("New Branch")
    client.delete_database("test happy path", "admin")
    assert client.db is None
    assert "test happy path" not in client.list_databases()
 def test_simple_path_query(self):
     woql_object = WOQLQuery().path("v:X", "scm:hop", "v:Y", "v:Path")
     json_object = {
         "@type": "woql:Path",
         "woql:subject": {
             "@type": "woql:Variable",
             "woql:variable_name": {
                 "@value": "X",
                 "@type": "xsd:string"
             },
         },
         "woql:path_pattern": {
             "@type": "woql:PathPredicate",
             "woql:path_predicate": {
                 "@id": "scm:hop"
             },
         },
         "woql:object": {
             "@type": "woql:Variable",
             "woql:variable_name": {
                 "@value": "Y",
                 "@type": "xsd:string"
             },
         },
         "woql:path": {
             "@type": "woql:Variable",
             "woql:variable_name": {
                 "@value": "Path",
                 "@type": "xsd:string"
             },
         },
     }
     assert woql_object.to_dict() == json_object
示例#10
0
 def test_woql_as_method(self):
     [x, y, z] = WOQLQuery().vars("x", "y", "z")
     query = WOQLQuery().woql_as(x).woql_as(y).woql_as(z)
     assert query.to_dict() == [
         {
             "@type": "Column",
             "indicator": {
                 "@type": "Indicator",
                 "index": 0
             },
             "variable": "x",
         },
         {
             "@type": "Column",
             "indicator": {
                 "@type": "Indicator",
                 "index": 1
             },
             "variable": "y",
         },
         {
             "@type": "Column",
             "indicator": {
                 "@type": "Indicator",
                 "index": 2
             },
             "variable": "z",
         },
     ]
    def test_graph_method(self):
        woql_object = WOQLQuery().node("a", "AddQuad").graph("schema/main")
        woql_object2 = (WOQLQuery().node(
            "doc:x", "add_quad").graph("schema/main").label("my label", "en"))

        assert woql_object.to_dict() == {}
        assert woql_object2.to_dict() == WOQL_JSON["graphMethodJson"]
示例#12
0
 def test_grouped_path_query(self):
     woql_object = WOQLQuery().path("v:X", "(<hop,hop>)+", "v:Y", "v:Path")
     json_object = {
         "@type": "Path",
         "subject": {
             "@type": "NodeValue",
             "variable": "X",
         },
         "pattern": {
             "@type": "PathPlus",
             "plus": {
                 "@type":
                 "PathSequence",
                 "sequence": [
                     {
                         "@type": "InversePathPredicate",
                         "predicate": "hop",
                     },
                     {
                         "@type": "PathPredicate",
                         "predicate": "hop",
                     },
                 ],
             },
         },
         "object": {
             "@type": "Value",
             "variable": "Y",
         },
         "path": {
             "@type": "Value",
             "variable": "Path",
         },
     }
     assert woql_object.to_dict() == json_object
示例#13
0
 def test_delete_method(self):
     woql_object = WOQLQuery().delete_document("x")
     json_obj = {
         "@type": "DeleteDocument",
         "identifier": {
             "@type": "NodeValue",
             "node": "x"
         },
     }
     assert woql_object.to_dict() == json_obj
 def test_woql_or_method(self):
     woql_object = WOQLQuery().woql_or(WOQLQuery().triple("a", "b", "c"),
                                       WOQLQuery().triple("1", "2", "3"))
     woql_object2 = WOQLQuery().triple("a", "b", "c") | WOQLQuery().triple(
         "1", "2", "3")
     assert woql_object.to_dict() == WOQL_OR_JSON
     assert woql_object2.to_dict() == WOQL_OR_JSON
 def test_woql_not_method(self):
     woql_object = WOQLQuery().woql_not(WOQLQuery().triple("a", "b", "c"))
     woql_object_chain = WOQLQuery().woql_not()
     woql_object_chain.triple("a", "b", "c")
     json_obj = {
         "@type": "woql:Not",
         "woql:query": {
             "@type": "woql:Triple",
             "woql:subject": {
                 "@type": "woql:Node",
                 "woql:node": "doc:a"
             },
             "woql:predicate": {
                 "@type": "woql:Node",
                 "woql:node": "scm:b"
             },
             "woql:object": {
                 "@type": "woql:Datatype",
                 "woql:datatype": {
                     "@type": "xsd:string",
                     "@value": "c"
                 },
             },
         },
     }
     assert woql_object.to_dict() == json_obj
     assert woql_object_chain.to_dict() == json_obj
示例#16
0
 def test_path_method(self):
     query = WOQLQuery().path(
         "v:person",
         "((capability_userstory|userstory_gap){1,2})",
         "v:circle",
         "v:path_var5",
     )
     assert (
         query.to_json() ==
         '{"@type": "Path", "object": {"@type": "Value", "variable": "circle"}, "path": {"@type": "Value", "variable": "path_var5"}, "pattern": {"@type": "PathTimes", "from": 1, "times": {"@type": "PathOr", "or": [{"@type": "PathPredicate", "predicate": "capability_userstory"}, {"@type": "PathPredicate", "predicate": "userstory_gap"}]}, "to": 2}, "subject": {"@type": "NodeValue", "variable": "person"}}'
     )
示例#17
0
 def test_post_method(self):
     woql_object = WOQLQuery().post("my_json_file", {"format": "panda_json"})
     json_obj = {
         "@type": "woql:PostResource",
         "woql:file": {"@type": "xsd:string", "@value": "my_json_file"},
         "woql:format": {
             "@type": "woql:Format",
             "woql:format_type": {"@value": "panda_json", "@type": "xsd:string"},
         },
     }
     assert woql_object.to_dict() == json_obj
示例#18
0
 def test_remote_method(self):
     woql_object = WOQLQuery().remote({"url": "http://url"})
     json_obj = {
         "@type": "QueryResource",
         "format": "csv",
         "source": {
             "@type": "Source",
             "url": "http://url"
         },
     }
     assert woql_object.to_dict() == json_obj
 def test_doctype_property_method(self, property_without,
                                  property_with_des):
     woql_object = WOQLQuery().doctype("Journey").property(
         "Duration", "dateTime")
     woql_object_des = (WOQLQuery().doctype("Journey").property(
         "Duration",
         "dateTime",
         label="Journey Duration",
         description="Journey duration in minutes.",
     ))
     assert woql_object.to_dict() == property_without
     assert woql_object_des.to_dict() == property_with_des
示例#20
0
 def test_start_method(self):
     woql_object = WOQLQuery().limit(10).start(0).star()
     json_obj = {
         "@type": "Limit",
         "limit": 10,
         "query": {
             "@type": "Start",
             "query": WOQL_STAR,
             "start": 0
         },
     }
     assert woql_object.to_dict() == json_obj
 def test_woql_sum_method(self):
     woql_object = WOQLQuery().sum([1, 2, 8], "v:output")
     json_obj = {
         "@type": "woql:Sum",
         "woql:sum_list": {
             "@type":
             "woql:Array",
             "woql:array_element": [
                 {
                     "@type": "woql:ArrayElement",
                     "woql:datatype": {
                         "@type": "xsd:integer",
                         "@value": 1
                     },
                     "woql:index": {
                         "@type": "xsd:nonNegativeInteger",
                         "@value": 0
                     },
                 },
                 {
                     "@type": "woql:ArrayElement",
                     "woql:datatype": {
                         "@type": "xsd:integer",
                         "@value": 2
                     },
                     "woql:index": {
                         "@type": "xsd:nonNegativeInteger",
                         "@value": 1
                     },
                 },
                 {
                     "@type": "woql:ArrayElement",
                     "woql:datatype": {
                         "@type": "xsd:integer",
                         "@value": 8
                     },
                     "woql:index": {
                         "@type": "xsd:nonNegativeInteger",
                         "@value": 2
                     },
                 },
             ],
         },
         "woql:sum": {
             "@type": "woql:Variable",
             "woql:variable_name": {
                 "@value": "output",
                 "@type": "xsd:string"
             },
         },
     }
     assert woql_object.to_dict() == json_obj
示例#22
0
 def test_multi_using(self):
     woql_object = WOQLQuery()
     woql_object.woql_and(
         WOQLQuery().using(
             "admin/dbName/local/commit/commitID_1",
             WOQLQuery().triple("v:A", "v:B", "v:C"),
         ),
         WOQLQuery().using(
             "admin/dbName/local/commit/commitID_2",
             WOQLQuery().woql_not(WOQLQuery().triple("v:A", "v:B", "v:C")),
         ),
     )
     assert woql_object.to_dict() == WoqlExtra["multiUsingJson"]
 def test_cast_method_object(self):
     woql_object1 = WOQLQuery().cast("my_int",
                                     "xsd:integer",
                                     "v:Duration_Cast",
                                     literal_type="owl:Thing")
     woql_object2 = WOQLQuery().cast("my_int",
                                     "xsd:integer",
                                     "v:Duration_Cast",
                                     literal_type="woql:node")
     woql_object3 = WOQLQuery().cast(WOQLQuery().iri("my_int"),
                                     "xsd:integer", "v:Duration_Cast")
     assert woql_object1.to_dict() == woql_object3.to_dict()
     assert woql_object2.to_dict() == woql_object3.to_dict()
示例#24
0
 def test_eq_method(self):
     woql_object = WOQLQuery().eq("a", "b")
     json_obj = {
         "@type": "Equals",
         "left": {
             "@type": "Value",
             "node": "a",
         },
         "right": {
             "@type": "Value",
             "node": "b"
         },
     }
     assert woql_object.to_dict() == json_obj
示例#25
0
 def test_member_method(self):
     woql_object = WOQLQuery().member("v:member", "v:list_obj")
     json_obj = {
         "@type": "Member",
         "member": {
             "@type": "Value",
             "variable": "member",
         },
         "list": {
             "@type": "Value",
             "variable": "list_obj",
         },
     }
     assert woql_object.to_dict() == json_obj
示例#26
0
 def test_insert_method(self):
     woql_object = WOQLQuery().insert_document("x", "iri")
     json_obj = {
         "@type": "InsertDocument",
         "document": {
             "@type": "Value",
             "node": "x"
         },
         "identifier": {
             "@type": "NodeValue",
             "node": "iri"
         },
     }
     assert woql_object.to_dict() == json_obj
示例#27
0
 def test_read_method(self):
     woql_object = WOQLQuery().read_document("iri", "output")
     json_obj = {
         "@type": "ReadDocument",
         "document": {
             "@type": "Value",
             "node": "output"
         },
         "identifier": {
             "@type": "NodeValue",
             "node": "iri"
         },
     }
     assert woql_object.to_dict() == json_obj
示例#28
0
 def test_eq_method(self):
     woql_object = WOQLQuery().eq("a", "b")
     json_obj = {
         "@type": "woql:Equals",
         "woql:left": {
             "@type": "woql:Datatype",
             "woql:datatype": {"@type": "xsd:string", "@value": "a"},
         },
         "woql:right": {
             "@type": "woql:Datatype",
             "woql:datatype": {"@type": "xsd:string", "@value": "b"},
         },
     }
     assert woql_object.to_dict() == json_obj
示例#29
0
 def test_get_method(self):
     woql_object = WOQLQuery().get(WOQLQuery().woql_as("a", "b"), "Target")
     json_obj = {
         "@type": "woql:Get",
         "woql:as_vars": [
             {
                 "@type": "woql:NamedAsVar",
                 "woql:identifier": {"@type": "xsd:string", "@value": "a"},
                 "woql:variable_name": {"@type": "xsd:string", "@value": "b"},
             }
         ],
         "woql:query_resource": "Target",
     }
     assert woql_object.to_dict() == json_obj
示例#30
0
 def test_member_method(self):
     woql_object = WOQLQuery().member("v:member", "v:list_obj")
     json_obj = {
         "@type": "woql:Member",
         "woql:member": {
             "@type": "woql:Variable",
             "woql:variable_name": {"@value": "member", "@type": "xsd:string"},
         },
         "woql:member_list": {
             "@type": "woql:Variable",
             "woql:variable_name": {"@value": "list_obj", "@type": "xsd:string"},
         },
     }
     assert woql_object.to_dict() == json_obj