Example #1
0
    def to_graph(self, graph=None, node=None, td_nodes=None):
        if node is None:
            node = BNode()
        if graph is None:
            graph = bound_graph()

        if (node, None, None) in graph:
            return graph

        graph.add((node, RDF.type, MAP.Mapping))
        graph.add((node, MAP.predicate, URIRef(self.predicate)))
        graph.add((node, MAP.key, Literal(self.key)))
        graph.add((node, MAP.rootMode, Literal(self.root)))
        if self.path:
            graph.add((node, MAP.jsonPath, Literal(self.path)))
        if self.target_class:
            graph.add((node, MAP.targetClass, URIRef(self.target_class)))
        elif self.target_datatype:
            graph.add((node, MAP.targetDatatype, URIRef(self.target_datatype)))
        if self.transform:
            if isinstance(self.transform, ResourceTransform):
                transform_node = td_nodes.get(self.transform.td, None) if td_nodes else None
            else:
                transform_node = BNode()
                self.transform.to_graph(graph=graph, node=transform_node)

            if transform_node:
                graph.add((node, MAP.valuesTransformedBy, transform_node))

        return graph
Example #2
0
    def to_graph(self, graph=None, node=None, td_nodes=None):
        if node is None:
            node = BNode()
        if graph is None:
            graph = bound_graph(identifier=str(node))

        if (node, None, None) in graph:
            return graph

        graph.add((node, RDF.type, MAP.AccessMapping))

        if td_nodes:
            if self.endpoint not in td_nodes:
                td_nodes[self.endpoint] = BNode()
            e_node = td_nodes[self.endpoint]
        else:
            e_node = self.endpoint.node or BNode()

        graph.add((node, MAP.mapsResourcesFrom, e_node))
        self.endpoint.to_graph(graph=graph, node=e_node)

        for m in self.mappings:
            if td_nodes:
                if m not in td_nodes:
                    td_nodes[m] = BNode()
                m_node = td_nodes[m]
            else:
                m_node = BNode()
            m.to_graph(graph=graph, node=m_node, td_nodes=td_nodes)
            graph.add((node, MAP.hasMapping, m_node))

        if self.__order is not None:
            graph.add((node, MAP.order, Literal(self.order)))

        return graph
Example #3
0
    def to_graph(self, graph=None, node=None, td_nodes=None, th_nodes=None, abstract=False):
        if node is None:
            node = self.node or BNode()
        if graph is None:
            graph = bound_graph(str(node))

        if td_nodes is None:
            td_nodes = {td: td.node for td in self.tds}
        if th_nodes is None:
            th_nodes = {r: r.node for r in self.resources}

        graph.add((node, RDF.type, CORE.Ecosystem))
        roots = self.roots
        for td in self.tds:
            if td in roots:
                graph.add(
                    (node, CORE.hasComponent,
                     td.resource.node if not th_nodes else th_nodes.get(td.resource.node, td.resource.node)))

            if not abstract:
                td_node = td_nodes.get(td, None) if td_nodes else None
                for ext in td.extends:
                    ext.to_graph(graph=graph, node=ext.node, td_nodes=td_nodes, th_nodes=th_nodes)
                td.to_graph(graph=graph, node=td_node, td_nodes=td_nodes, th_nodes=th_nodes)

        for root in filter(lambda x: not isinstance(x, TD), self.roots):
            graph.add((node, CORE.hasComponent, root.node))
            root.to_graph(graph)

        return graph
Example #4
0
 def __init__(self, uri=None, types=None):
     # type: (any, iter) -> None
     self.__graph = bound_graph(identifier=uri)
     self.__node = uri
     if self.__node is None:
         self.__node = BNode()
     if types is None:
         types = []
     self.__types = set(types)
     for t in self.__types:
         self.__graph.add((self.__node, RDF.type, URIRef(t)))
Example #5
0
    def to_graph(self, graph=None, node=None, **kwargs):
        if node is None:
            node = BNode()
        if graph is None:
            graph = bound_graph(str(node))

        if (node, None, None) in graph:
            return graph

        graph.add((node, RDF.type, MAP.SPARQLQuery))
        graph.add((node, MAP.queryText, Literal(self.query)))
        graph.add((node, MAP.sparqlHost, Literal(self.host)))

        return graph
Example #6
0
    def to_graph(self, graph=None, node=None, **kwargs):
        if node is None:
            node = BNode()
        if graph is None:
            graph = bound_graph(str(node))

        if (node, None, None) in graph:
            return graph

        graph.add((node, RDF.type, MAP.StringReplacement))
        graph.add((node, MAP.match, Literal(self.match)))
        graph.add((node, MAP['replace'], Literal(self.replace)))

        return graph
Example #7
0
    def to_graph(self, graph=None, node=None, td_nodes=None, th_nodes=None, abstract=False):
        if node is None:
            node = td_nodes.get(self, BNode()) if td_nodes else (self.node or BNode())

        if graph is None:
            graph = bound_graph(str(node))

        if (node, None, None) in graph:
            return graph

        resource_node = self.resource.node
        if th_nodes:
            resource_node = th_nodes.get(resource_node, resource_node)

        graph.add((node, RDF.type, CORE.ThingDescription))
        graph.add((node, CORE.describes, resource_node))
        graph.add((node, CORE.identifier, Literal(self.id)))
        for ext in self.extends:
            graph.add((node, CORE.extends, td_nodes.get(ext, ext.node)))

        if not abstract:
            for am in self.__access_mappings:
                if td_nodes:
                    if am not in td_nodes:
                        td_nodes[am] = BNode()
                    am_node = td_nodes[am]
                else:
                    am_node = BNode()
                graph.add((node, MAP.hasAccessMapping, am_node))
                am.to_graph(graph=graph, node=am_node, td_nodes=td_nodes)

            for rdfs in self.rdf_sources:
                if td_nodes:
                    if rdfs not in td_nodes:
                        td_nodes[rdfs] = BNode()
                    r_node = td_nodes[rdfs]
                else:
                    r_node = BNode()
                graph.add((node, MAP.fromRDFSource, r_node))
                rdfs.to_graph(graph=graph, node=r_node)

            r_node = self.resource.node
            if not (th_nodes is None or r_node in th_nodes):
                r_graph = self.resource.to_graph()
                for s, p, o in r_graph:
                    ss = th_nodes.get(s, s) if th_nodes else s
                    oo = th_nodes.get(o, o) if th_nodes else o
                    graph.add((ss, p, oo))

        return graph
Example #8
0
    def to_graph(self, graph=None, node=None, td_nodes=None, th_nodes=None, abstract=False):
        if node is None:
            node = self.node or BNode()
        if graph is None:
            graph = bound_graph(str(node))

        eco_node = self.ecosystem.node
        self.ecosystem.to_graph(graph=graph, node=eco_node, td_nodes=td_nodes, th_nodes=th_nodes, abstract=abstract)
        graph.add((node, RDF.type, CORE.ThingEcosystemDescription))
        graph.add((node, CORE.describes, eco_node))

        if td_nodes:
            for td_node in td_nodes.values():
                if isinstance(td_node, TD):
                    graph.add((node, CORE.usesTD, td_node))

        return graph
Example #9
0
    def to_graph(self, graph=None, node=None):
        if node is None:
            node = self.node or BNode()
        if graph is None:
            graph = bound_graph(identifier=str(node))

        if (node, None, None) in graph:
            return graph

        graph.add((node, RDF.type, WOT.Link))
        if self.href:
            graph.add((node, WOT.href, Literal(self.href)))
        if self.whref:
            graph.add((node, WOT.withHRef, Literal(self.whref)))
        graph.add((node, WOT.mediaType, Literal(self.media)))

        return graph