Slight difference between result formating surf.allegrograph and surf.sparql, can this be unified?

13 views
Skip to first unread message

Laurens

unread,
Oct 9, 2012, 8:46:06 AM10/9/12
to sur...@googlegroups.com
When switching from Allegrograph to SPARQL Wrapper I get following issue that result.bindings is not always the same type because of the two differen implentations of the readers result formatting:

http://code.google.com/p/surfrdf/source/browse/trunk/plugins/surf.sparql_protocol/sparql_protocol/reader.py?r=362

def _to_table(self, result):
        if not isinstance(result, dict):
            return result

        if not "results" in result:
            return result

        converted = []
        for binding in result["results"]["bindings"]:
            rdf_item = {}
            for key, obj in binding.items():
                try:
                    rdf_item[key] = json_to_rdflib(obj)
                except ValueError:
                    continue

            converted.append(rdf_item)

        return converted


http://code.google.com/p/surfrdf/source/browse/trunk/plugins/surf.allegro_franz/allegro_franz/reader.py?r=362

def _to_table(self, result):
>         table = []
>         bindings = result.getBindingNames()
>         for bindingSet in result:
>             row = {}
>             for key in bindings:
>                 try:    v = toRdfLib(bindingSet[key])
>                 except: v = None
>                 row[key] = v
>             table.append(row)
>         return table


Expected should be something like: https://gist.github.com/3705219 in the handling code for both cases, now this only works in one of the cases.

So the question is would it be possible to unify both methods such that they return the same kind of result table?
Reply all
Reply to author
Forward
0 new messages