grewpy package

Submodules

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

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

given two corpora, outputs the number of common edges, only left ones and only right ones

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

Bases: AbstractCorpus

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

get(sent_id)[source]

return a graph corresponding to the sentence id sent_id

get_all()[source]

return a dictionary mapping sentence ids to graphs

get_id()[source]

return the id of the corpus

get_sent_ids()[source]

return the list of sentence ids

search(request, clustering_parameter=[], clustering_keys=[], flat=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

to_conll()[source]

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)[source]

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

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]
from_triples(triples)[source]
greater(n, s)[source]

return True if n > s in g

json_data()[source]
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

to_conll()[source]

return a CoNLL string for the given graph

to_dot()[source]

return a string in dot/graphviz format

triples()[source]

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

grewpy.grew.request_counter()[source]
grewpy.grew.set_config(data)[source]

Change the configuration used in the next exchanges See https://grew.fr/doc/graph/#edges for details about config

grewpy.grs module

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

Bases: Command

safe()[source]

return a clause list for a safe request

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

Bases: object

json_data()[source]
safe()[source]

return a clause list for a safe request

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

Bases: list

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

Bases: Command

safe()[source]

return a clause list for a safe request

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

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

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

run a Grs on a graph :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 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

onf(strat_name='main')[source]
rules()[source]
safe_rules()[source]

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]
json_data()[source]
packages()[source]
rules()[source]
strategies()[source]
class grewpy.grs.Request(*L)[source]

Bases: object

lists of ClauseList

append(*L)[source]

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]
json_data()[source]
pattern()[source]

return the pattern of self as a tuple

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

Bases: object

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

Bases: object

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

Module contents

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