@@ -49,6 +49,10 @@ def __init__(self, name):
4949    def  __str__ (self ):
5050        return  self .name 
5151
52+     def  to_dict (self ):
53+         return  {"@type" : "Value" ,
54+                 "variable" : self .name }
55+ 
5256
5357class  Doc :
5458    def  __init__ (self , dictionary ):
@@ -58,6 +62,9 @@ def __init__(self, dictionary):
5862    def  __str__ (self ):
5963        return  str (self .dictionary )
6064
65+     def  to_dict (self ):
66+         return  self .encoded 
67+ 
6168    def  _convert (self , obj ):
6269        if  type (obj ) is  str :
6370            return  {"@type" : "Value" , "data" : {"@type" : "xsd:string" , "@value" : obj }}
@@ -363,9 +370,9 @@ def _clean_subject(self, obj):
363370    def  _clean_predicate (self , predicate ):
364371        """Transforms whatever is passed in as the predicate (id or variable) into the appropriate json-ld form""" 
365372        pred  =  False 
366-         if  type (predicate )  is   dict :
373+         if  isinstance (predicate ,  dict ) :
367374            return  predicate 
368-         if  type (predicate )  !=   str :
375+         if  not   isinstance (predicate ,  str ) :
369376            raise  ValueError ("Predicate must be a URI string" )
370377            return  str (predicate )
371378        if  ":"  in  predicate :
@@ -716,7 +723,7 @@ def using(self, collection, subq=None):
716723        if  self ._cursor .get ("@type" ):
717724            self ._wrap_cursor_with_and ()
718725        self ._cursor ["@type" ] =  "Using" 
719-         if  not  collection  or  type (collection )  !=   str :
726+         if  not  collection  or  not   isinstance (collection ,  str ) :
720727            raise  ValueError (
721728                "The first parameter to using must be a Collection ID (string)" 
722729            )
@@ -888,7 +895,7 @@ def woql_from(self, graph, query=None):
888895        if  self ._cursor .get ("@type" ):
889896            self ._wrap_cursor_with_and ()
890897        self ._cursor ["@type" ] =  "From" 
891-         if  not  graph  or  type (graph )  !=   str :
898+         if  not  graph  or  not   isinstance (graph ,  str ) :
892899            raise  ValueError (
893900                "The first parameter to from must be a Graph Filter Expression (string)" 
894901            )
@@ -914,7 +921,7 @@ def into(self, graph_descriptor, query):
914921        if  self ._cursor .get ("@type" ):
915922            self ._wrap_cursor_with_and ()
916923        self ._cursor ["@type" ] =  "Into" 
917-         if  not  graph_descriptor  or  type (graph_descriptor )  !=   str :
924+         if  not  graph_descriptor  or  not   isinstance (graph_descriptor ,  str ) :
918925            raise  ValueError (
919926                "The first parameter to from must be a Graph Filter Expression (string)" 
920927            )
@@ -1257,7 +1264,7 @@ def substr(self, string, length, substring, before=0, after=0):
12571264        if  not  substring :
12581265            substring  =  length 
12591266            length  =  len (substring ) +  before 
1260-         if  not  string  or  not  substring  or  type (substring )  !=   str :
1267+         if  not  string  or  not  substring  or  not   isinstance (substring ,  str ) :
12611268            raise  ValueError (
12621269                "Substr - the first and last parameters must be strings representing the full and substring variables / literals" 
12631270            )
0 commit comments