grewpy package


grewpy.corpus module

Grew module : anything you want to talk about graphs Graphs are represented either by a dict (called dict-graph), or by an str (str-graph).

class grewpy.corpus.AbstractCorpus[source]

Bases: object

edge_diff(other, edge_criterion=<function AbstractCorpus.<lambda>>)[source]

given two corpora, outputs the number of common edges, only left ones and only right ones. It also outputs precision, recall and f-measure.

edge_diff_up_to(other, edge_transform=<function AbstractCorpus.<lambda>>)[source]
class grewpy.corpus.Corpus(data)[source]

Bases: AbstractCorpus

apply(Grs, strat='main')[source]

clean the corpus (remove from the backend memory)

count(request, clustering_parameter=[], clustering_keys=[], flat=False)[source]

Count for [request] into [corpus_index] :param request: a string request :param corpus_index: an integer given by the [corpus] function :return: the number of matching of [request] into the corpus


return a graph corresponding to the sentence id sent_id


return a dictionary mapping sentence ids to graphs


return the id of the corpus


return the list of sentence ids

run(Grs, strat='main')[source]
search(request, clustering_parameter=[], clustering_keys=[], flat=None, deco=False, bound=None, timeout=None)[source]

Search for [request] into [corpus_index]

Parameters: request (Request): a request corpus_index: an integer given by the [corpus] function

Returns: list: the list of matching of [request] into the corpus


return a CoNLL string for the current corpus

class grewpy.corpus.CorpusDraft(data=None)[source]

Bases: AbstractCorpus, dict

the draft is composed of
  • self, a dict mapping sentence_id to graphs

  • self._sent_ids, a list that specifies the sentence order


Apply fun to all graphs, return the new Corpus


grewpy.graph module

Grew module: anything you want to talk about graphs

class grewpy.graph.Fs_edge(data)[source]

Bases: dict

static decompose_edge(s)[source]
static extract(u, clauses, key='1')[source]
class grewpy.graph.Graph(data=None, **kwargs)[source]

Bases: object

a dict mapping node keys to feature structure

with extra data:
  • an extra dict sucs mapping node keys to successors (pair of edge feature,node key)

  • the list order containing nodes linearly ordered

  • and the `meta`(data) as a dict

Param data: either
  • None: return an empty graph

  • a json formatted string

  • a file name containing a json/conll

  • a Graph: return a copy of the graph

  • or named arguments: features, sucs, meta and order

apply(Grs, strat='main')[source]
edge(n, m)[source]

given node n and m return the “first” label of an edge between n and m if it exists

edge_diff(other, edge_criterion=<function Graph.<lambda>>) array[source]

edge difference between two graphs

edge_diff_up_to(other, edge_transform=<function Graph.<lambda>>)[source]
edge_up_to(n, m, criterion)[source]
edges(n, m)[source]

given node n and m, return the set of edges between n and m

edges_up_to(n, m, criterion)[source]

search for edges between n and m verifying some criterion

classmethod from_json(data_json)[source]
greater(n, s)[source]

return True if n > s in g

lower(n, m)[source]

given node n and m in g: return True if n < m in g

run(Grs, strat='main')[source]
property sucs

successor relation


return a CoNLL string for the given graph


return a string in dot/graphviz format


return a SVG code for the given graph

to_svg(deco=None, draw_root=False)[source]

return a SVG code for the given graph


return the list of edges presented as triples (n,e,s) with n-[e]-> s

grewpy.grew module

Grew module : anything you want to talk about graph rewriting systems Graphs are represented by dictionaries (nodes, edges, meta informations) GRS can be build via files, explicit constructions or even strings. See doc of GREW

exception grewpy.grew.GrewError(message)[source]

Bases: Exception

A wrapper for grew-related errors


Change the configuration used in the next exchanges See for details about config

grewpy.grs module

class grewpy.grs.Add_edge(X, e, Y)[source]

Bases: Command


return a clause list for a safe request

class grewpy.grs.Command(s)[source]

Bases: object


return a clause list for a safe request

class grewpy.grs.Commands(*L)[source]

Bases: list

classmethod from_json(json_data)[source]
class grewpy.grs.Delete_edge(X, e, Y)[source]

Bases: Command


return a clause list for a safe request

class grewpy.grs.Delete_feature(X, f)[source]

Bases: Command

class grewpy.grs.GRS(args)[source]

Bases: object

An abstract GRS. Offers the possibility to apply rewriting. The object is abstract and cannot be changed. For that, use a GRSDraft

UD2bUD = <grewpy.grs.GRS object>
apply(data, strat='main', abstract=True)[source]

run a Grs on a graph or corpus :param grs_data: a graph rewriting system or a Grew string representation of a grs :param G: the graph, either a str (in grew format) or a dict :param strat: the strategy (by default “main”) :return: the rewritten graph and an error if there is not exaclty one output graph

run(data, strat='main')[source]

run a Grs on a graph :param data: a graph or an AbstractCorpus :param strat: the strategy (by default “main”) :return: a dictionary mapping sid to the list of rewritten graphs

class grewpy.grs.GRSDraft(args=None)[source]

Bases: Package

A GRSDraft is a structure that gives access to the internals of a Graph Rewriting System: packages, rules, patterns, strategies, etc It cannot be used to perform rewriting, for that, use a GRS


create a new grs with application of safe to each rule. self.rules() are supposed to contain only Commands of length 1 that support safe method

class grewpy.grs.Package[source]

Bases: dict

dict mapping names to rule/package/strategies

classmethod from_json(json_data)[source]
class grewpy.grs.Request(*L)[source]

Bases: object

lists of ClauseList


Append a new ClauseList to the Request L is given either as a pair (s,t) with “s in {‘pattern’,’without’,’meta’} and t : str or L[0] is a ClauseList

classmethod from_json(json_data)[source]
classmethod parse(string_request)[source]

return the pattern of self as a tuple

class grewpy.grs.RequestItem(sort: str, *L)[source]

Bases: object

classmethod from_json(json_data: Any)[source]
class grewpy.grs.Rule(request: Request, cmd_list: Commands, lexicons=None)[source]

Bases: object

classmethod from_json(json_data)[source]

Module contents

Grew python library All you need to use grew See grew online documentation for global informations