Request the planner a search plan for a given gp and returns the plan as a graph.
        :param gp:
        :return:
544174
def __get_gp_plan(self, gp):
        
        query = urlencode({'gp': gp})
        response = requests.get('{}/plan?'.format(self.__planner) + query, headers={'Accept': 'text/turtle'})
        graph = Graph()
        try:
            graph.parse(source=StringIO.StringIO(response.text), format='turtle')
        except BadSyntax:
            pass
        return graph
105725
def graph(self, **kw):
        
        self.name = kw.get('name', 'G')
        self.fillcolor = kw.get('fillcolor', '#ffffff')
        self.fontcolor = kw.get('fontcolor', '#000000')
        self.rankdir = kw.get('rankdir', 'BT' if self.reverse else 'TB')
        if kw.get('concentrate', True):
            self.concentrate = 'concentrate = true;'
        else:
            self.concentrate = ''
        self.dedent("""
            digraph {self.name} {{
                {self.concentrate}
                rankdir = {self.rankdir};
                node [style=filled,fillcolor="{self.fillcolor}",fontcolor="{self.fontcolor}",fontname=Helvetica,fontsize=10];

        """.format(self=self))
        yield
        self.writeln('}')
619039
def search(self, keyword):
        
        params = {
            "source": "map",
            "description": keyword
        }
        data = self._request(ENDPOINTS['SEARCH'], params)
        data['result_data'] = [res for res in data['result_data'] if isinstance(res, dict)]
        return data
1232730
def make_graph_pygraphviz(self, recs, nodecolor,
                              edgecolor, dpi,
                              draw_parents=True, draw_children=True):
        """"""
        import pygraphviz as pgv

        grph = pgv.AGraph(name="GO tree")

        edgeset = set()
        for rec in recs:
            if draw_parents:
                edgeset.update(rec.get_all_parent_edges())
            if draw_children:
                edgeset.update(rec.get_all_child_edges())

        edgeset = [(self.label_wrap(a), self.label_wrap(b))
                   for (a, b) in edgeset]

        # add nodes explicitly via add_node
        # adding nodes implicitly via add_edge misses nodes
        # without at least one edge
        for rec in recs:
            grph.add_node(self.label_wrap(rec.item_id))

        for src, target in edgeset:
            # default layout in graphviz is top->bottom, so we invert
            # the direction and plot using dir="back"
            grph.add_edge(target, src)

        grph.graph_attr.update(dpi="%d" % dpi)
        grph.node_attr.update(shape="box", style="rounded,filled",
                              fillcolor="beige", color=nodecolor)
        grph.edge_attr.update(shape="normal", color=edgecolor,
                              dir="back", label="is_a")
        # highlight the query terms
        for rec in recs:
            try:
                node = grph.get_node(self.label_wrap(rec.item_id))
                node.attr.update(fillcolor="plum")
            except:
                continue

        return grph
1309763
def mcp(self, *args, **kwargs):
        
        # Create Cost surface to work on
        self.mcp_cost = graph.MCP_Geometric(self.raster, *args, **kwargs)
353512
def draw_graph( g, fmt='svg', prg='dot', options={} ):
    
    # Convert RDF to Graphviz
    buf = StringIO()
    rdf2dot( g, buf, options )

    gv_options = options.get('graphviz',[])
    if fmt == 'png':
        gv_options += [ '-Gdpi=220', '-Gsize=25,10!' ]
        metadata = { "width": 5500, "height": 2200, "unconfined" : True }

    #import codecs
    #with codecs.open('/tmp/sparqlkernel-img.dot','w',encoding='utf-8') as f:
    #    f.write( buf.getvalue() )
    
    # Now use Graphviz to generate the graph
    image = run_dot( buf.getvalue(), fmt=fmt, options=gv_options, prg=prg )

    #with open('/tmp/sparqlkernel-img.'+fmt,'w') as f:
    #    f.write( image )

    # Return it
    if fmt == 'png':
        return { 'image/png' : base64.b64encode(image).decode('ascii') }, \
               { "image/png" : metadata }
    elif fmt == 'svg':
        return { 'image/svg+xml' : image.decode('utf-8').replace('<svg','<svg class="unconfined"',1) }, \
               { "unconfined" : True }
853414
def search_patients(self, search_criteria,
                        include_picture='N', organization_id=None):
        
        include_picture = include_picture or ''
        organization_id = organization_id or ''
        magic = self._magic_json(action=TouchWorksMagicConstants.ACTION_SEARCH_PATIENTS,
                                 app_name=self._app_name,
                                 token=self._token.token,
                                 parameter1=search_criteria,
                                 parameter2=include_picture,
                                 parameter3=organization_id)
        response = self._http_request(TouchWorksEndPoints.MAGIC_JSON, data=magic)
        result = self._get_results_or_raise_if_magic_invalid(
            magic,
            response,
            TouchWorksMagicConstants.RESULT_SEARCH_PATIENTS)
        return result
1334335
def geo_search(user_id, search_location):
    
    url = "https://api.twitter.com/1.1/geo/search.json"
    params =  {"query" : search_location }
    response = make_twitter_request(url, user_id, params).json()
    return response
1361727
def get_geometry_from_mp_symbol(self, mp_symbol):
        
        for gg in self.cg_list:
            if gg.mp_symbol == mp_symbol:
                return gg
        raise LookupError(
            'No coordination geometry found with mp_symbol "{symbol}"'.format(
                symbol=mp_symbol))
538070
def bind_graph(graph=None):
    
    if graph is None:
        graph = Graph()
    for prefix, ns in GRAPH_BINDINGS.items():
        graph.bind(prefix, ns, True)
    return graph
81512
def as_graph(self) -> Graph:  # pragma: no cover
        """"""
        if Graph is None:
            raise ImportError('The graphviz package is required to draw the graph.')
        graph = Graph()
        nodes_left = {}  # type: Dict[TLeft, str]
        nodes_right = {}  # type: Dict[TRight, str]
        node_id = 0
        for (left, right), value in self._edges.items():
            if left not in nodes_left:
                name = 'node{:d}'.format(node_id)
                nodes_left[left] = name
                graph.node(name, label=str(left))
                node_id += 1
            if right not in nodes_right:
                name = 'node{:d}'.format(node_id)
                nodes_right[right] = name
                graph.node(name, label=str(right))
                node_id += 1
            edge_label = value is not True and str(value) or ''
            graph.edge(nodes_left[left], nodes_right[right], edge_label)
        return graph
133685
def search(**kw):
    
    portal = get_portal()
    catalog = ICatalog(portal)
    catalog_query = ICatalogQuery(catalog)
    query = catalog_query.make_query(**kw)
    return catalog(query)
358125
def uri_to_graph(uri, **kwargs):
    '''
    
    '''
    s = kwargs.get('session', requests.Session())
    graph = rdflib.Graph()
    try:
        res = s.get(uri)
    except requests.ConnectionError as e:
        raise ProviderUnavailableException("URI not available: %s" % uri)
    if res.status_code == 404:
        return False
    graph.parse(data=res.content)
    return graph
106685
def show_graph_summary(g):
    
    sample_data = []
    print("list(g[RDFS.Class]) = " + str(len(list(g[RDFS.Class]))))
    # Get Subject Lists
    num_subj = 0
    for subj in g.subjects(RDF.type):
        num_subj += 1
        if num_subj < 5:
            sample_data.append("subjects.subject: " + get_string_from_rdf(subj))
    print("g.subjects(RDF.type) = " + str(num_subj))
    
    # Get Sample of Subjects, Predicates, Objects
    num_subj = 0
    for subj, pred, obj in g:
        num_subj += 1
        if num_subj < 5:
            sample_data.append("g.subject   : " + get_string_from_rdf(pred))
            sample_data.append("g.predicate : " + get_string_from_rdf(subj))
            sample_data.append("g.object    : " + get_string_from_rdf(obj))
            
    print("g.obj(RDF.type) = " + str(num_subj))
    
    
    print ("------ Sample Data ------")
    for line in sample_data:
        print(line)
539588
def get_fragment(self, **kwargs):
        
        gen, namespaces, plan = self.get_fragment_generator(**kwargs)
        graph = ConjunctiveGraph()
        [graph.bind(prefix, u) for (prefix, u) in namespaces]
        [graph.add((s, p, o)) for (_, s, p, o) in gen]

        return graph
217839
def get_plans(self, reference):
        
        response = make_request(
            '{}charm?charm-url={}'.format(self.url,
                                          'cs:' + reference.path()),
            timeout=self.timeout, client=self._client)
        try:
            return tuple(map(lambda plan: Plan(
                url=plan['url'], plan=plan['plan'],
                created_on=datetime.datetime.strptime(
                    plan['created-on'],
                    "%Y-%m-%dT%H:%M:%SZ"
                ),
                description=plan.get('description'),
                price=plan.get('price')), response))
        except Exception as err:
            log.error(
                'cannot process plans: invalid JSON response: {!r}'.format(
                    response))
            raise ServerError(
                'unable to get list of plans for {}: {}'.format(
                    reference.path(), err))
103613
def createPlan(self, plan, thread_id=None):
        
        thread_id, thread_type = self._getThread(thread_id, None)

        data = {
            "event_type": "EVENT",
            "event_time": plan.time,
            "title": plan.title,
            "thread_id": thread_id,
            "location_id": plan.location_id or "",
            "location_name": plan.location or "",
            "acontext": ACONTEXT,
        }
        j = self._post(self.req_url.PLAN_CREATE, data, fix_request=True, as_json=True)