Commit e78975c2 authored by Bruno Guillaume's avatar Bruno Guillaume

add lib_usage page

parent 529967e7
+++
Categories = ["Development","GoLang"]
Tags = ["Development","golang"]
Description = ""
date = "2018-03-13T16:40:34+01:00"
title = "lib_usage"
menu = "main"
+++
# Example of library usage with several GRS applied sequentially.
The graph representation has changed in version 0.47 and now each graph is aware of its relative domain.
The usage of the library is simpler (see the old version for comparison).
In the code below, 3 different GRS are loaded (you will need to adapt full path to your local install):
* `pos_to_ssq`
* `ssq_to_dsq`
* `dsq_to_deep`
The file with the code below: `lib_usage.ml` ([Download](/lib_usage/lib_usage.ml)) can be compiled with the command:
`ocamlbuild -use-ocamlfind -pkgs 'libgrew, libgrew, conll, yojson, log, containers, str, ANSITerminal' lib_usage.native`
```ocaml
{{< input file="/static/lib_usage/lib_usage.ml" >}}
```
# Obsolete: Example of version 0.46 library usage with several GRS applied sequentially.
Example with version 0.46 of the library.
:warning: A graph is defined relatively to a particular domain and using it with the wrong domain may produced unwanted effects and erroneous graphs.
In the code below, 3 different GRS are loaded (you will need to adapt full path to your local install):
* `pos_to_ssq`
* `ssq_to_dsq`
* `dsq_to_deep`
The output of the first GRS `graph1__pos_to_ssq` is defined relatively to the domain of the same GRS `pos_to_ssq`.
To be used as the input of the GRS `ssq_to_dsq`, it must be converted to the domain of the new GRS `ssq_to_dsq`.
The converted version of `graph1` is `graph1__ssq_to_dsq`.
Again, the output of `ssq_to_dsq` must be converted before being used as an input to the next GRS `dsq_to_deep` (see below).
```ocaml
{{< input file="/static/lib_usage/lib_usage_0.46.ml" >}}
```
open Libgrew
open Conll
let pos_to_ssq = Grs.load "/users/guillaum/gitlab/grew/POStoSSQ/grs/surf_synt_main.grs"
let ssq_to_dsq = Grs.load "/users/guillaum/gitlab/grew/SSQtoDSQ/grs/main_dsq.grs"
let dsq_to_deep = Grs.load "/users/guillaum/gitlab/deep-sequoia/tools/sequoia_proj.grs"
let main () =
let pos = "La/DET/le souris/NC/souris a/V/avoir été/VPP/être mangée/VPP/manger par/P/par le/DET/le chat/NC/chat" in
let pos_graph = Graph.of_brown pos in
let ssq_graph = match Rewrite.simple_rewrite ~gr:pos_graph ~grs:pos_to_ssq ~strat:"main" with
| [one] -> one
| _ -> failwith "[pos_to_ssq] several graphs: not managed" in
let dsq_graph = match Rewrite.simple_rewrite ~gr:ssq_graph ~grs:ssq_to_dsq ~strat:"main" with
| [one] -> one
| _ -> failwith "[ssq_to_dsq] several graphs: not managed" in
let deep_graph = match Rewrite.simple_rewrite ~gr:dsq_graph ~grs:dsq_to_deep ~strat:"deep" with
| [one] -> one
| _ -> failwith "[dsq_to_deep] several graphs: not managed" in
Printf.printf "========= ssq_graph =========\n%s" (Conll.to_string (Graph.to_conll ssq_graph));
Printf.printf "========= dsq_graph =========\n%s" (Conll.to_string (Graph.to_conll dsq_graph));
Printf.printf "========= deep_graph =========\n%s" (Conll.to_string (Graph.to_conll deep_graph));
()
let _ = main ()
open Libgrew
open Conll
let pos_to_ssq = Grs.load "/users/guillaum/gitlab/grew/POStoSSQ/grs/surf_synt_main.grs"
let dom_pos_to_ssq = Grs.domain pos_to_ssq
let ssq_to_dsq = Grs.load "/users/guillaum/gitlab/grew/SSQtoDSQ/grs/main_dsq.grs"
let dom_ssq_to_dsq = Grs.domain ssq_to_dsq
let dsq_to_deep = Grs.load "/users/guillaum/gitlab/deep-sequoia/tools/sequoia_proj.grs"
let dom_dsq_to_deep = Grs.domain dsq_to_deep
let main () =
let pos = "La/DET/le souris/NC/souris a/V/avoir été/VPP/être mangée/VPP/manger par/P/par le/DET/le chat/NC/chat" in
let graph_0 = Graph.of_brown pos in
let graph1__pos_to_ssq = match Rewrite.simple_rewrite ~gr:graph_0 ~grs:pos_to_ssq ~strat:"main" with
| [one] -> one
| _ -> failwith "[pos_to_ssq] several graphs: not managed" in
let conll1 = Graph.to_conll ?domain:dom_pos_to_ssq graph1__pos_to_ssq in
let graph1__ssq_to_dsq = Graph.of_conll ?domain:dom_ssq_to_dsq conll1 in
let graph2__ssq_to_dsq = match Rewrite.simple_rewrite ~gr:graph1__ssq_to_dsq ~grs:ssq_to_dsq ~strat:"main" with
| [one] -> one
| _ -> failwith "[ssq_to_dsq] several graphs: not managed" in
let conll2 = Graph.to_conll ?domain:dom_ssq_to_dsq graph2__ssq_to_dsq in
let graph2__dsq_to_deep = Graph.of_conll ?domain:dom_dsq_to_deep conll1 in
let graph3__dsq_to_deep = match Rewrite.simple_rewrite ~gr:graph2__dsq_to_deep ~grs:dsq_to_deep ~strat:"deep" with
| [one] -> one
| _ -> failwith "[ssq_to_dsq] several graphs: not managed" in
let conll3 = Graph.to_conll ?domain:dom_dsq_to_deep graph3__dsq_to_deep in
Printf.printf "========= graph1 =========\n%s" (Conll.to_string conll1);
Printf.printf "========= graph2 =========\n%s" (Conll.to_string conll2);
Printf.printf "========= graph3 =========\n%s" (Conll.to_string conll3);
()
let _ = main ()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment