def toJsonLD(self, destination=None, nice_output=False): """ Method that exports the descriptor of a WebThing in a JSON-LD file pointed to by 'destination', if available. The output can be also seen as table on stdout, if 'nice_output' is True. """ result = self._sepa.query("JSONLD_TD_CONSTRUCT", forcedBindings={"thing": self.uri}, destination=destination) if nice_output: tablify(result, prefix_file=self._sepa.sap.get_namespaces(stringList=True)) jld_result = jldFileBuilder(result, frame=json_ld_frame) if destination is not None: try: if isinstance(destination, TextIOBase): print(jld_result, file=destination) else: with open(destination, "w") as jld_output: print(jld_result, file=jld_output) except Exception as e: logger.error("Unable to export json-ld file: {}".format(e)) return jld_result
def discover(sepa, td_uri="UNDEF", ip_type="UNDEF", nice_output=False): """ Generic InteractionPattern discovery. Can be more selective by giving 'td_uri' and 'ip_type' params. 'nice_output' prints to console a table with the result. """ d_output = sepa.query("DISCOVER_INTERACTION_PATTERNS", forcedBindings={ "td_uri": td_uri, "ipattern_type_specific": ip_type }) if nice_output: tablify(d_output, prefix_file=sepa.get_namespaces(stringList=True)) return d_output
def test_1(self): self.engine.update("INSERT_GREETING") result = self.engine.query_all() self.assertEqual( tablify(result, prefix_file=self.prefixes, destination=None), EXPECTED_TABLE_test1)
def diff_JsonQuery(jA, jB, ignore_val=[], show_diff=False, log_message=""): """ Compares outputs of query json jA towards jB. You can ignore specific bindings values in 'ignore_val'. When 'show_diff' is true, tablaze.py is called for nicer visualization of differences. 'log_message' can be used for verbose notification. Returns True or False as comparison result. """ result = True diff = [] for bindingA in jA["results"]["bindings"]: eq_binding = False for bindingB in jB["results"]["bindings"]: eq_binding = cfr_bindings(bindingA, bindingB, ignore_val) if eq_binding: break if not eq_binding: diff.append(bindingA) result = False if show_diff and len(diff) > 0: jdiff = json.loads('{}') jdiff["head"] = {"vars": jA["head"]["vars"]} jdiff["results"] = {"bindings": diff} logger.warning("{} Differences:\n{}".format( log_message, tablify(jdiff, destination=None))) return result
def discover(sepa, ds="UNDEF", nice_output=False): """ Discovers dataschemas in the knowedge base. Can be more selective by defining 'ds' field, and print nice output setting to True the 'nice_output' flag. """ d_output = sepa.query("GET_DATASCHEMAS", forcedBindings={"ds_force": ds}) if nice_output: d_output = tablify(d_output, prefix_file=sepa.sap.get_namespaces(stringList=True), destination=None) return d_output
def discover(sepa, bindings={}, nice_output=False): """ Thing discovery. It can be more selective when we use 'bindings', while 'nice_output' prints the results to console in a friendly manner. """ d_output = sepa.query("DISCOVER_THINGS", bindings) if nice_output: d_output = tablify( d_output, prefix_file=sepa.sap.get_namespaces(stringList=True), destination=None) return d_output
def discover(sepa, action="UNDEF", nice_output=False): """ Static method, used to discover actions in the rdf store. 'action' by default is 'UNDEF', retrieving every action. Otherwise it will be more selective 'nice_output' prints a nice table on console, using tablaze. """ d_output = sepa.query("DESCRIBE_ACTION", forcedBindings={"action_uri": action}) if nice_output: d_output = tablify(d_output, prefix_file=sepa.sap.get_namespaces(stringList=True), destination=None) if (action != "UNDEF") and (len(d_output["results"]["bindings"]) > 1): raise Exception("Action discovery gave more than one result") return d_output
def discover(sepa, prop="UNDEF", nice_output=False): """ Static method, used to discover properties in the rdf store. 'prop' by default is 'UNDEF', retrieving every property. Otherwise it will be more selective. 'nice_output' prints a nice table on console, using tablaze. """ d_output = sepa.query( "DESCRIBE_PROPERTY", forcedBindings={"property_uri": prop}) if nice_output: d_output = tablify(d_output, prefix_file=sepa.sap.get_namespaces(stringList=True), destination=None) if (prop != "UNDEF") and (len(d_output["results"]["bindings"]) > 1): raise Exception("Property discovery gave more than one result") return d_output