├── test ├── test-Base.test ├── test-BigLexicon.fromScratch ├── test-Comb1.input ├── test-Comb2.input ├── test-IfPos.input ├── test-Disjunction1.input ├── test-Disjunction2.input ├── test-Comb1.test ├── test-Base.input ├── test-Adj.test ├── test-BigLexicon.input ├── test-Comb1.lexicon ├── test-FreeLinkedVariables.input ├── test-IfPos.test ├── test-Disjunction2.test ├── test-Base.lexicon ├── test-FreeLinkedVariables.test ├── test-Foreach.input ├── test-FreeLinkedVariables.lexicon ├── test-Disjunction1.lexicon ├── test-Disjunction2.lexicon ├── test-Adj.input ├── test-Disjunction1.test ├── test-Adj.macros ├── test-InheritedSynthesized.pattern ├── test-InheritedSynthesized.input ├── test-Comb2.lexicon ├── test-IfPos.lexicon ├── test-FreeLinkedVariables.rules ├── test-InheritedSynthesized.morpho ├── test-Comb1.rules ├── test-Base.rules ├── test-Disjunction1.rules ├── test-InheritedSynthesized.macros ├── test-Adj.lexicon ├── test-Disjunction2.rules ├── test-BigLexicon.lexicon ├── test-Comb2.rules ├── test-BigLexicon.macros ├── test-En.macros ├── test-IfPos.rules ├── test-InheritedSynthesized.rules ├── test-Foreach.lexicon ├── test-BigLexicon.rules ├── test-Adj.rules ├── test-Foreach.rules ├── test-InheritedSynthesized.lexicon ├── test-Foreach.test ├── test-InheritedSynthesized.test ├── test-BigLexicon.test ├── test-En.stdin └── test-En.pattern ├── doc ├── doc-en.pdf ├── doc-en.synctex.gz ├── doc-en.out └── doc-en.aux ├── AUTHORS.md ├── src ├── postedition_fr.py ├── config.hpp ├── buildlexicon.hpp ├── parser_exception.hpp ├── config.hpp.in ├── usage_exception.hpp ├── uniq-id.hpp ├── fatal_exception.hpp ├── usage_exception.cc ├── variableflag.hpp ├── parser_exception.cc ├── serializable.hpp ├── compacted-lexicon-buffer.hpp ├── memoization-value.hpp ├── compacted-lexicon-info.hpp ├── fatal_exception.cc ├── memoization-map.hpp ├── variableflag.cc ├── compacted-lexicon-fsa.hpp ├── uniq-id.cc ├── forestmap.hpp ├── facade.hpp ├── compacted-lexicon-tree.hpp ├── shared_ptr.hpp ├── bitset.hpp ├── flags.hpp ├── forestidentifier.hpp ├── entry.hpp ├── lexicon.hpp ├── entries.hpp ├── forest.hpp ├── itemset.hpp ├── listfeatures.hpp ├── memoization-value.cc ├── rules.hpp ├── environment.hpp ├── compacted-lexicon-info.cc ├── serializable.cc ├── terms.hpp ├── postedition_en.l ├── statements.hpp ├── compacted-lexicon-buffer.cc ├── node.hpp ├── forestmap.cc ├── messages.hpp ├── forestidentifier.cc ├── memoization-map.cc ├── compacted-lexicon.hpp ├── facade.cc ├── vartable.hpp ├── feature.hpp ├── lexicon.cc ├── pairp.hpp ├── parser.hpp ├── compacted-lexicon-fsa.cc ├── flags.cc ├── postedition_fr.l ├── features.hpp ├── rule.hpp ├── entry.cc ├── entries.cc ├── value.hpp ├── generator.hpp ├── bitset.cc ├── itemset.cc ├── terms.cc ├── listfeatures.cc └── forest.cc ├── INSTALL.md ├── script.py ├── CMakeLists.txt └── xsl └── xml2CS-dot-graph.xsl /test/test-Base.test: -------------------------------------------------------------------------------- 1 | a b-98 2 | -------------------------------------------------------------------------------- /test/test-BigLexicon.fromScratch: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/test-Comb1.input: -------------------------------------------------------------------------------- 1 | S [] 2 | -------------------------------------------------------------------------------- /test/test-Comb2.input: -------------------------------------------------------------------------------- 1 | S [] 2 | -------------------------------------------------------------------------------- /test/test-IfPos.input: -------------------------------------------------------------------------------- 1 | S [] 2 | -------------------------------------------------------------------------------- /test/test-Disjunction1.input: -------------------------------------------------------------------------------- 1 | S[] 2 | -------------------------------------------------------------------------------- /test/test-Disjunction2.input: -------------------------------------------------------------------------------- 1 | S[] 2 | -------------------------------------------------------------------------------- /test/test-Comb1.test: -------------------------------------------------------------------------------- 1 | c 2 | bc 3 | ac 4 | -------------------------------------------------------------------------------- /test/test-Base.input: -------------------------------------------------------------------------------- 1 | S [HEAD:X, a:xxx] 2 | 3 | -------------------------------------------------------------------------------- /test/test-Adj.test: -------------------------------------------------------------------------------- 1 | large square-section pink iron 2 | -------------------------------------------------------------------------------- /test/test-BigLexicon.input: -------------------------------------------------------------------------------- 1 | Axiom [HEAD:LEXEME_5] 2 | -------------------------------------------------------------------------------- /test/test-Comb1.lexicon: -------------------------------------------------------------------------------- 1 | a a; 2 | b b; 3 | c c; 4 | -------------------------------------------------------------------------------- /test/test-FreeLinkedVariables.input: -------------------------------------------------------------------------------- 1 | S [a:a, b:$x] 2 | 3 | -------------------------------------------------------------------------------- /test/test-IfPos.test: -------------------------------------------------------------------------------- 1 | cb dc 2 | b ca db 3 | a ca da 4 | -------------------------------------------------------------------------------- /test/test-Disjunction2.test: -------------------------------------------------------------------------------- 1 | b c 2 | a c f 3 | b c d 4 | b c e 5 | -------------------------------------------------------------------------------- /test/test-Base.lexicon: -------------------------------------------------------------------------------- 1 | a a[HEAD:X]; 2 | "b-$xxx" b[HEAD:X, xxx:$xxx]; 3 | -------------------------------------------------------------------------------- /test/test-FreeLinkedVariables.test: -------------------------------------------------------------------------------- 1 | [a:a, b:?, c:?] [a:a, b:a, c:a] 2 | -------------------------------------------------------------------------------- /test/test-Foreach.input: -------------------------------------------------------------------------------- 1 | S [HEAD:VOITURE, mod:<[HEAD:BEAU],[HEAD:JAUNE]>] 2 | -------------------------------------------------------------------------------- /doc/doc-en.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lionelclement/Elvex/HEAD/doc/doc-en.pdf -------------------------------------------------------------------------------- /test/test-FreeLinkedVariables.lexicon: -------------------------------------------------------------------------------- 1 | "[a:$x, b:$y, c:$k]" a[a:$x, b:$y, c:$k]; 2 | -------------------------------------------------------------------------------- /test/test-Disjunction1.lexicon: -------------------------------------------------------------------------------- 1 | a a; 2 | b b; 3 | c c; 4 | d d; 5 | e e; 6 | f f; 7 | -------------------------------------------------------------------------------- /test/test-Disjunction2.lexicon: -------------------------------------------------------------------------------- 1 | a a; 2 | b b; 3 | c c; 4 | d d; 5 | e e; 6 | f f; 7 | -------------------------------------------------------------------------------- /test/test-Adj.input: -------------------------------------------------------------------------------- 1 | S [mod:<[HEAD:iron],[HEAD:pink],[HEAD:square_section],[HEAD:large]>] 2 | -------------------------------------------------------------------------------- /doc/doc-en.synctex.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lionelclement/Elvex/HEAD/doc/doc-en.synctex.gz -------------------------------------------------------------------------------- /test/test-Disjunction1.test: -------------------------------------------------------------------------------- 1 | c 2 | cd 3 | ac 4 | bc 5 | ce 6 | cf 7 | bcf 8 | acf 9 | bce 10 | ace 11 | bcd 12 | acd 13 | -------------------------------------------------------------------------------- /test/test-Adj.macros: -------------------------------------------------------------------------------- 1 | @size = [type:size] ; 2 | @color= [type:color]; 3 | @shape= [type:shape] ; 4 | @material= [type:material] ; 5 | 6 | -------------------------------------------------------------------------------- /test/test-InheritedSynthesized.pattern: -------------------------------------------------------------------------------- 1 | // lexeme pos lemma features 2 | 3 | CHAUVE_SOURIS noun CHAUVE_SOURIS [@f] 4 | 5 | // end 6 | 7 | -------------------------------------------------------------------------------- /test/test-InheritedSynthesized.input: -------------------------------------------------------------------------------- 1 | S [HEAD:CHAUVE_SOURIS, mod:<[FORM:"(this is an input form $X)"]>, attr1:56, attr2:"--- $X ---", attr3:a|b, attr4:$X] 2 | -------------------------------------------------------------------------------- /test/test-Comb2.lexicon: -------------------------------------------------------------------------------- 1 | aa aa; 2 | ab ab; 3 | ac ac; 4 | ad ad; 5 | ae ae; 6 | af af; 7 | 8 | ba ba; 9 | bb bb; 10 | bc bc; 11 | bd bd; 12 | be be; 13 | bf bf; 14 | 15 | ca ca; 16 | cb cb; 17 | cc cc; 18 | cd cd; 19 | ce ce; 20 | cf cf; 21 | -------------------------------------------------------------------------------- /test/test-IfPos.lexicon: -------------------------------------------------------------------------------- 1 | a a; 2 | b b; 3 | ca ca; 4 | cb cb; 5 | cc cc; 6 | cd cd; 7 | ce ce; 8 | cf cf; 9 | da da; 10 | db db; 11 | dc dc; 12 | dd dd; 13 | de de; 14 | df df; 15 | ea ea; 16 | eb eb; 17 | ec ec; 18 | ed ed; 19 | ee ee; 20 | ef ef; 21 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | # Authors 2 | 3 | - **Lionel Clément** 4 | - *Affiliation:* Univ. Bordeaux, CNRS, Bordeaux INP, LaBRI, UMR 5800 5 | - *Address:* 351, cours de la Libération 6 | 33405 Talence Cedex - France 7 | - *Email:* lionel.clement|at|u-bordeaux.fr 8 | 9 | -------------------------------------------------------------------------------- /test/test-FreeLinkedVariables.rules: -------------------------------------------------------------------------------- 1 | @trace 2 | S → A A 3 | { 4 | printlnstderr __FILE__, "..."; 5 | [a:$x]; 6 | ↓1 = ↑; 7 | ↓2 = ⇓1 U [b:$x]; 8 | } 9 | 10 | @trace 11 | A → a 12 | { 13 | [b:$x] ⊂ ↑; 14 | ↓1 = ↑ U [c:$x]; 15 | ⇑ = ⇓1; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /test/test-InheritedSynthesized.morpho: -------------------------------------------------------------------------------- 1 | // *********************************************************** 2 | // Nouns 3 | // ***********************************************************/ 4 | chauve souris noun CHAUVE_SOURIS [@s] 5 | chauves souris noun CHAUVE_SOURIS [@p] 6 | 7 | // end 8 | -------------------------------------------------------------------------------- /test/test-Comb1.rules: -------------------------------------------------------------------------------- 1 | @withoutSpaces 2 | S → [A | B] C 3 | { 4 | ↓1 = []; 5 | ↓2 = []; 6 | } 7 | 8 | @withoutSpaces 9 | A → a 10 | { 11 | ↓1 = []; 12 | } 13 | 14 | @withoutSpaces 15 | B → b 16 | { 17 | ↓1 = []; 18 | } 19 | 20 | @withoutSpaces 21 | C → c 22 | { 23 | ↓1 = []; 24 | } 25 | -------------------------------------------------------------------------------- /test/test-Base.rules: -------------------------------------------------------------------------------- 1 | @trace 2 | S → A B 3 | { 4 | printlnstderr __FILE__, "..."; 5 | [a:$a] ⊂ ↑; 6 | ↓1 = ↑; 7 | ↓2 = ⇓1 U [a:$a]; 8 | } 9 | 10 | @trace 11 | A → a 12 | { 13 | ↓1 = ↑; 14 | ⇑ = ⇓1; 15 | } 16 | 17 | @trace 18 | B → b 19 | { 20 | [HEAD:X]; 21 | [a:$a] ⊂ ↑; 22 | ↓1 = [HEAD:X, $a:98]; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /test/test-Disjunction1.rules: -------------------------------------------------------------------------------- 1 | @withoutSpaces 2 | S → [A | B] C [D | E | F] 3 | { 4 | printlnstderr __FILE__, "..."; 5 | ↓1 = ↑; 6 | ↓2 = ↑; 7 | ↓3 = ↑; 8 | } 9 | 10 | A → a 11 | { 12 | ↓1 = ↑; 13 | } 14 | 15 | B → b 16 | { 17 | ↓1 = ↑; 18 | } 19 | 20 | C → c 21 | { 22 | ↓1 = ↑; 23 | } 24 | 25 | D → d 26 | { 27 | ↓1 = ↑; 28 | } 29 | 30 | E → e 31 | { 32 | ↓1 = ↑; 33 | } 34 | 35 | F → f 36 | { 37 | ↓1 = ↑; 38 | } 39 | -------------------------------------------------------------------------------- /test/test-InheritedSynthesized.macros: -------------------------------------------------------------------------------- 1 | // @macro features 2 | @s= [number:singular]; 3 | @p= [number:plural]; 4 | @m= [gender:masc]; 5 | @f= [gender:fem]; 6 | @ms= [@m, @s]; 7 | @mp= [@m, @p]; 8 | @fs= [@f, @s]; 9 | @fp= [@f, @p]; 10 | @_1= [person:one]; 11 | @_2= [person:two]; 12 | @_12= [person:one|two]; 13 | @_3= [person:three]; 14 | @_1s= [@_1, @s]; 15 | @_2s= [@_2, @s]; 16 | @_12s= [@_12, @s]; 17 | @_3s= [@_3, @s]; 18 | @def= [def:true]; 19 | 20 | 21 | -------------------------------------------------------------------------------- /test/test-Adj.lexicon: -------------------------------------------------------------------------------- 1 | big adj [HEAD:big, @size]; 2 | large adj [HEAD:large, @size]; 3 | 4 | yellow adj [HEAD:yellow, @color]; 5 | red adj [HEAD:red, @color]; 6 | pink adj [HEAD:pink, @color]; 7 | black adj [HEAD:black, @color]; 8 | 9 | square adj [HEAD:square, @shape]; 10 | "square-section" adj [HEAD:square_section, @shape]; 11 | 12 | iron adj [HEAD:iron, @material]; 13 | 14 | ring noun [HEAD:ring, number:sg]; 15 | cat noun [HEAD:cat, number:sg]; 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/test-Disjunction2.rules: -------------------------------------------------------------------------------- 1 | S → [A | B] C [D | E | F] 2 | { 3 | printlnstderr __FILE__, "..."; 4 | ↓1 = ↑; 5 | ↓2 = ↑; 6 | ↓3 = ↑; 7 | attest (↓3 => #1); 8 | attest (#1.1 <=> #3.3); 9 | } 10 | 11 | A → a 12 | { 13 | ↓1 = ↑; 14 | } 15 | 16 | B → b 17 | { 18 | ↓1 = ↑; 19 | } 20 | 21 | C → c 22 | { 23 | ↓1 = ↑; 24 | } 25 | 26 | D → d 27 | { 28 | ↓1 = ↑; 29 | } 30 | 31 | E → e 32 | { 33 | ↓1 = ↑; 34 | } 35 | 36 | F → f 37 | { 38 | ↓1 = ↑; 39 | } 40 | -------------------------------------------------------------------------------- /test/test-BigLexicon.lexicon: -------------------------------------------------------------------------------- 1 | 2 | /************************************************************ 3 | * Forms 4 | ************************************************************/ 5 | FORM form; 6 | 7 | /************************************************************ 8 | * Variable words 9 | ************************************************************/ 10 | "[attrMorpho:$attrMorpho,attrPattern:$attrPattern,attrInteger:$attrInteger,attrString:\"$attrString\"]" POS_2 [attrMorpho:$attrMorpho, attrPattern:$attrPattern,attrInteger:$attrInteger,attrString:$attrString]; 11 | 12 | -------------------------------------------------------------------------------- /test/test-Comb2.rules: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * Start 3 | ************************************************** */ 4 | S → [A | B] C 5 | { 6 | printlnstderr __FILE__, "..."; 7 | ↓1 = []; 8 | ↓2 = []; 9 | } 10 | 11 | @permutable 12 | A → [aa] ab [ac] ad [ae|af] 13 | { 14 | ↓1 = []; 15 | ↓2 = []; 16 | ↓3 = []; 17 | ↓4 = []; 18 | ↓5 = []; 19 | } 20 | 21 | @bidirectional 22 | B → [ba|bb] bc|bd [be|bf] 23 | { 24 | ↓1 = []; 25 | ↓2 = []; 26 | ↓3 = []; 27 | } 28 | 29 | C → [ca|cb] 30 | { 31 | ↓1 = []; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/postedition_fr.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | def transform_morphology(text): 4 | 5 | le, la, de, je, me, te, se, ce, ne, que + 6 | jusque, lorsque, puisque, quelque, quoique, parce que, quoi que, tel que 7 | si + il 8 | 9 | 10 | 11 | text = re.sub(r'\b([nNdDjJlL])[ea]\s+([hH]?[aAeEiIoOuUyY]|â|Â|à|À|é|É|è|È|ê|Ê|ë|Ë|î|Î|ï|Ï|ö|Ö|ô|Ô|ü|Ü|û|Û)', r"\1'\2", text, flags=re.IGNORECASE) 12 | text = re.sub(r'\b([mMtTsS])[e]\s+([aAeEiIoOuUyY]|â|Â|à|À|é|É|è|È|ê|Ê|ë|Ë|î|Î|ï|Ï|ö|Ö|ô|Ô|ü|Ü|û|Û)', r"\1'\2", text, flags=re.IGNORECASE) 13 | 14 | return text 15 | 16 | # Exemple d'utilisation 17 | input_text = "le haricot" 18 | transformed_text = transform_morphology(input_text) 19 | print(transformed_text) 20 | -------------------------------------------------------------------------------- /test/test-BigLexicon.macros: -------------------------------------------------------------------------------- 1 | /************************************************************ 2 | * Patterns 3 | ************************************************************/ 4 | @m = [gender:ms]; 5 | @f = [gender:fm]; 6 | @_1 = [person:one]; 7 | @_2 = [person:two]; 8 | @_12 = [person:one|two]; 9 | @_13 = [person:one|three]; 10 | @_3 = [person:three]; 11 | @s = [number:sg]; 12 | @p = [number:pl]; 13 | @_1s = [@_1, @s]; 14 | @_2s = [@_2, @s]; 15 | @_12s = [@_12, @s]; 16 | @_13s = [@_13, @s]; 17 | @_3s = [@_3, @s]; 18 | @_1p = [@_1, @p]; 19 | @_2p = [@_2, @p]; 20 | @_3p = [@_3, @p]; 21 | @_3ms = [@_3s, @m]; 22 | @_3fs = [@_3s, @f]; 23 | @hum = [human:true]; 24 | @nohum = [human:false]; 25 | @def = [def:true]; 26 | -------------------------------------------------------------------------------- /test/test-En.macros: -------------------------------------------------------------------------------- 1 | /************************************************************ 2 | * Patterns 3 | ************************************************************/ 4 | @m = [gender:ms]; 5 | @f = [gender:fm]; 6 | @_1 = [person:one]; 7 | @_2 = [person:two]; 8 | @_12 = [person:one|two]; 9 | @_13 = [person:one|three]; 10 | @_3 = [person:three]; 11 | @s = [number:sg]; 12 | @p = [number:pl]; 13 | @_1s = [@_1, @s]; 14 | @_2s = [@_2, @s]; 15 | @_12s = [@_12, @s]; 16 | @_13s = [@_13, @s]; 17 | @_3s = [@_3, @s]; 18 | @_1p = [@_1, @p]; 19 | @_2p = [@_2, @p]; 20 | @_3p = [@_3, @p]; 21 | @_3ms = [@_3s, @m]; 22 | @_3fs = [@_3s, @f]; 23 | @hum = [human:true]; 24 | @nohum = [human:false]; 25 | @def = [def:true]; 26 | 27 | -------------------------------------------------------------------------------- /test/test-IfPos.rules: -------------------------------------------------------------------------------- 1 | S → [A|B] C D 2 | { 3 | printlnstderr __FILE__, "..."; 4 | if (#1) { 5 | ↓2 = [HEAD:CA]; 6 | if (#1.1) { 7 | ↓3 = [HEAD:DA]; 8 | } 9 | else { 10 | ↓3 = [HEAD:DB]; 11 | } 12 | } 13 | else { 14 | ↓2 = [HEAD:CB]; 15 | ↓3 = [HEAD:DC]; 16 | } 17 | ↓1 = []; 18 | } 19 | 20 | A → a 21 | { 22 | ↓1 = []; 23 | } 24 | 25 | B → b 26 | { 27 | ↓1 = []; 28 | } 29 | 30 | C → ca 31 | { 32 | [HEAD:CA]; 33 | ↓1 = []; 34 | } 35 | 36 | C → cb 37 | { 38 | [HEAD:CB]; 39 | ↓1 = []; 40 | } 41 | 42 | D → da 43 | { 44 | [HEAD:DA]; 45 | ↓1 = []; 46 | } 47 | 48 | D → db 49 | { 50 | [HEAD:DB]; 51 | ↓1 = []; 52 | } 53 | 54 | D → dc 55 | { 56 | [HEAD:DC]; 57 | ↓1 = []; 58 | } 59 | -------------------------------------------------------------------------------- /src/config.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef CONFIG_H 21 | #define CONFIG_H 22 | 23 | #define ELVEX_VERSION_MAJOR "2" 24 | #define ELVEX_VERSION_MINOR "27" 25 | #define ELVEX_VERSION_PATCH "0" 26 | #define ELVEX_VERSION "2.27.0" 27 | #define PROJECT_NAME "elvex" 28 | 29 | #endif // CONFIG_H 30 | -------------------------------------------------------------------------------- /src/buildlexicon.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef BUILDLEXICON_HH_ 21 | #define BUILDLEXICON_HH_ 22 | 23 | namespace Buildlexicon 24 | { 25 | enum Choice 26 | { 27 | BUILD, 28 | CONSULT, 29 | LIST, 30 | NONE 31 | }; 32 | 33 | } 34 | 35 | #endif /* BUILDLEXICON_HH_ */ 36 | -------------------------------------------------------------------------------- /test/test-InheritedSynthesized.rules: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * Start 3 | ************************************************** */ 4 | @trace 5 | S → NP dot tag { 6 | printlnstderr __FILE__, "..."; 7 | [attr4:value4]; 8 | ↓1 = ↑; 9 | ↓2 = []; 10 | ↓3 = ↑; 11 | } 12 | 13 | @trace 14 | NP → det N { 15 | ↓2 = ↑; 16 | ↓1 = ⇓2; 17 | ⇑ = ⇓2; 18 | } 19 | 20 | @trace 21 | N → adj|adjForm N { 22 | [mod:<$Head::$Tail>, $Rest]; 23 | [number:$inhNb, gender:$inhGd] ⊂ ↑; 24 | ↓1 = $Head ∪ [number:$inhNb, gender:$inhGd] ∪ [number:$synthNb, gender:$synthGd]; 25 | ↓2 = [mod:$Tail, $Rest]; 26 | [gender:$synthGd, number:$synthNb] ⊂ ⇓2; 27 | ⇑ = ⇓2 ∪ [gender:$synthGd, number:$synthNb] ∪ [qual:yes]; 28 | } 29 | 30 | @trace 31 | N → noun { 32 | [mod:NIL]; 33 | ↓1 = ↑; 34 | ⇑ = ⇓1; 35 | } -------------------------------------------------------------------------------- /src/parser_exception.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_PARSER_EXCEPTION_HPP 21 | #define ELVEX_PARSER_EXCEPTION_HPP 22 | 23 | #include 24 | #include "fatal_exception.hpp" 25 | 26 | class parser_exception : public fatal_exception 27 | { 28 | 29 | public: 30 | parser_exception(std::string message); 31 | parser_exception(std::ostringstream &oss); 32 | }; 33 | 34 | #endif // ELVEX_PARSER_EXCEPTION_HPP 35 | -------------------------------------------------------------------------------- /src/config.hpp.in: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef CONFIG_H 21 | #define CONFIG_H 22 | 23 | #define ELVEX_VERSION_MAJOR "@PROJECT_VERSION_MAJOR@" 24 | #define ELVEX_VERSION_MINOR "@PROJECT_VERSION_MINOR@" 25 | #define ELVEX_VERSION_PATCH "@PROJECT_VERSION_PATCH@" 26 | #define ELVEX_VERSION "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@" 27 | #define PROJECT_NAME "@PROJECT_NAME@" 28 | 29 | #endif // CONFIG_H 30 | -------------------------------------------------------------------------------- /test/test-Foreach.lexicon: -------------------------------------------------------------------------------- 1 | la det [gender:fm]; 2 | le det [gender:ms]; 3 | 4 | voiture n [HEAD:VOITURE, gender:fm, number:sg, form:"voiture"]; 5 | véhicule n [HEAD:VOITURE, gender:ms, number:sg, form:"véhicule"]; 6 | bagnole n [HEAD:VOITURE, gender:fm, number:sg, form:"bagnole"]; 7 | voitures n [HEAD:VOITURE, gender:fm, number:pl , form:"voiture"]; 8 | véhicules n [HEAD:VOITURE, gender:ms, number:pl, form:"véhicule"]; 9 | bagnoles n [HEAD:VOITURE, gender:fm, number:pl, form:"bagnole"]; 10 | 11 | beau adj [HEAD:BEAU, gender:ms, number:sg, pos:pre, form:"beau"]; 12 | beaux adj [HEAD:BEAU, gender:ms, number:pl, pos:pre, form:"beaux"]; 13 | belle adj [HEAD:BEAU, gender:fm, number:sg, pos:pre, form:"belle"]; 14 | belles adj [HEAD:BEAU, gender:fm, number:pl, pos:pre, form:"belles"]; 15 | 16 | jaune adj [HEAD:JAUNE, number:sg, pos:post, form:"jaune"]; 17 | jaunes adj [HEAD:JAUNE, number:pl, pos:post, form:"jaunes"]; 18 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | ## Requirements 2 | 3 | To fully compile **Elvex**, make sure you have the following tools installed on your computer: 4 | 5 | - g++ 6 | - flex 7 | - bison 8 | - libxml2-dev 9 | - cmake 10 | 11 | ## Download 12 | 13 | To download **Elvex**, follow this command: 14 | 15 | ```shell 16 | git clone https://github.com/lionelclement/Elvex.git 17 | ``` 18 | 19 | ## Compilation 20 | 21 | To compile **Elvex**, follow these commands from the Elvex directory: 22 | 23 | 1. Run: `cmake .` 24 | 2. Run: `make -j 7` 25 | 3. Run: `sudo make install` 26 | 27 | ## Testing 28 | 29 | After you have successfully compiled **Elvex**, execute the following command: 30 | 31 | ```shell 32 | make -s -f Makefile.test test 33 | ``` 34 | 35 | To create your own projects, add your files to the 'test' directory with the correct file extensions and execute 36 | 37 | ```shell 38 | make -s -f Makefile.test test/.output 39 | ``` 40 | 41 | -------------------------------------------------------------------------------- /src/usage_exception.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_USAGE_EXCEPTION_HPP 21 | #define ELVEX_USAGE_EXCEPTION_HPP 22 | 23 | #include 24 | #include 25 | 26 | #include "fatal_exception.hpp" 27 | 28 | class usage_exception : 29 | public fatal_exception { 30 | 31 | public: 32 | usage_exception(std::string message); 33 | usage_exception(std::ostringstream& oss); 34 | 35 | }; 36 | 37 | 38 | #endif //ELVEX_USAGE_EXCEPTION_HPP 39 | -------------------------------------------------------------------------------- /src/uniq-id.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_UNIQ_ID_H 21 | #define ELVEX_UNIQ_ID_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | class UniqId 28 | { 29 | 30 | private: 31 | static uint32_t uniqId; 32 | uint32_t id; 33 | 34 | public: 35 | explicit UniqId(uint32_t id = 0); // if zero => autoinc 36 | uint32_t getId(void) const; 37 | std::string getIdStr(void) const; 38 | }; 39 | 40 | #endif // ELVEX_UNIQ_ID_H 41 | -------------------------------------------------------------------------------- /script.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | num_forms = 32 4 | num_lemmas = 1000 5 | #It will take a while ! 6 | #num_forms = 32 7 | #num_lemmas = 100 8 | 9 | with open(sys.argv[1], "w") as morphoFile: 10 | k = 0 11 | for i in range(1, num_lemmas + 1): 12 | for j in range(1, num_forms + 1): 13 | form = f"FORM_{i}_{j}" 14 | pos = f"POS_{i%2}" 15 | lemma = f"LEMMA_{i}" 16 | features = f"attrMorpho:_{i%17},attrInteger:{k},attrString:\"{k}\"" 17 | line = f"{form}\t{pos}\t{lemma}\t[{features}]\n" 18 | morphoFile.write(line) 19 | k = k+1 20 | 21 | with open(sys.argv[2], "w") as patternFile: 22 | for i in range(1, num_lemmas + 1): 23 | lexeme= f"LEXEME_{i}" 24 | pos = f"POS_{i%2}" 25 | lemma = f"LEMMA_{i}" 26 | features = f"attrPattern:_{i%13}" 27 | line = f"{lexeme}\t{pos}\t{lemma}\t[{features}]\n" 28 | patternFile.write(line) 29 | 30 | -------------------------------------------------------------------------------- /src/fatal_exception.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_FATAL_EXCEPTION_HPP 21 | #define ELVEX_FATAL_EXCEPTION_HPP 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | class fatal_exception : public std::exception 28 | { 29 | private: 30 | std::string message; 31 | 32 | public: 33 | fatal_exception(std::string message); 34 | fatal_exception(std::ostringstream &oss); 35 | const char* what() const noexcept override; 36 | }; 37 | 38 | #endif // ELVEX_FATAL_EXCEPTION_HPP 39 | -------------------------------------------------------------------------------- /src/usage_exception.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include "usage_exception.hpp" 21 | 22 | /* ************************************************** 23 | * 24 | ************************************************** */ 25 | usage_exception::usage_exception(std::string message): fatal_exception(message) { 26 | } 27 | 28 | /* ************************************************** 29 | * 30 | ************************************************** */ 31 | usage_exception::usage_exception(std::ostringstream& oss): fatal_exception(oss) { 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/variableflag.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_VARIABLE_FLAG_H 21 | #define ELVEX_VARIABLE_FLAG_H 22 | 23 | class VariableFlag 24 | { 25 | 26 | public: 27 | enum flagValues 28 | { 29 | CONTAINS, 30 | DOES_NOT_CONTAIN, 31 | NONE 32 | }; 33 | 34 | private: 35 | enum flagValues flag; 36 | 37 | public: 38 | VariableFlag(void) noexcept; 39 | 40 | bool containsVariable(void); 41 | 42 | void setFlag(enum flagValues flag); 43 | }; 44 | 45 | #endif // ELVEX_VARIABLE_FLAG_H 46 | -------------------------------------------------------------------------------- /src/parser_exception.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include "parser_exception.hpp" 21 | 22 | /* ************************************************** 23 | * 24 | ************************************************** */ 25 | parser_exception::parser_exception(std::string message) : fatal_exception(message) 26 | { 27 | } 28 | 29 | /* ************************************************** 30 | * 31 | ************************************************** */ 32 | parser_exception::parser_exception(std::ostringstream &oss) : fatal_exception(oss) 33 | { 34 | } 35 | -------------------------------------------------------------------------------- /src/serializable.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_SERIALIZABLE_H 21 | #define ELVEX_SERIALIZABLE_H 22 | 23 | #include 24 | 25 | class Serializable 26 | { 27 | 28 | private: 29 | size_t serialHashCode; 30 | 31 | virtual void makeSerialString() = 0; 32 | 33 | protected: 34 | std::string serialString; 35 | 36 | public: 37 | explicit Serializable(); 38 | 39 | virtual ~Serializable(); 40 | 41 | std::string peekSerialString(); 42 | 43 | size_t hash(); 44 | 45 | void resetSerial(); 46 | }; 47 | 48 | #endif // ELVEX_SERIALIZABLE_H 49 | -------------------------------------------------------------------------------- /test/test-BigLexicon.rules: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | ************************************************** */ 4 | @trace 5 | Axiom → A B { 6 | printlnstderr __FILE__, "..."; 7 | ↓1 = ↑; 8 | [attrPattern:$attrPattern, attrMorpho:$attrMorpho, attrInteger:$attrInteger, attrString:$attrString] ⊂ ⇓1; 9 | ↓2 = [attrPattern:$attrPattern, attrMorpho:$attrMorpho, attrInteger:$attrInteger, attrString:$attrString]; 10 | } 11 | 12 | /* ************************************************** 13 | * 14 | ************************************************** */ 15 | @trace 16 | A → POS_0 { 17 | ↓1 = ↑; 18 | ⇑ = ⇓1; 19 | } 20 | 21 | /* ************************************************** 22 | * 23 | ************************************************** */ 24 | @trace 25 | A → POS_1 form { 26 | ↓1 = ↑; 27 | ⇑ = ⇓1; 28 | ↓2 = [FORM:"..."]; 29 | 30 | } 31 | 32 | /* ************************************************** 33 | * 34 | ************************************************** */ 35 | @trace 36 | B → POS_2 { 37 | ↓1 = ↑; 38 | ⇑ = ⇓1; 39 | } 40 | -------------------------------------------------------------------------------- /src/compacted-lexicon-buffer.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef COMPACTEDLEXICONBUFFER_H 21 | #define COMPACTEDLEXICONBUFFER_H 22 | 23 | #include 24 | 25 | struct CompactedLexiconBuffer 26 | { 27 | private: 28 | uint32_t next; 29 | uint32_t offset; 30 | 31 | public: 32 | CompactedLexiconBuffer(uint32_t next, uint32_t offset); 33 | 34 | CompactedLexiconBuffer(void); 35 | 36 | uint32_t getOffset() const; 37 | 38 | uint32_t getNext() const; 39 | 40 | bool isNext() const; 41 | 42 | bool isOffset() const; 43 | 44 | void print(std::ostream &) const; 45 | }; 46 | 47 | #endif // COMPACTEDLEXICONBUFFER_H 48 | -------------------------------------------------------------------------------- /test/test-Adj.rules: -------------------------------------------------------------------------------- 1 | @trace 2 | S → [ADJ] [ADJ] [ADJ] [ADJ] [ADJ] [ADJ] [ADJ] [ADJ] 3 | { 4 | printlnstderr __FILE__, "..."; 5 | [mod:$modifiers]; 6 | foreach $modifier in $modifiers { 7 | $entries = search $modifier on adj; 8 | foreach $entry in $entries { 9 | [type:$type] ⊂ $entry; 10 | if ($type == size) { 11 | ↓1 = $modifier; 12 | } else if ($type == age) { 13 | ↓2 = $modifier; 14 | } else if ($type == shape) { 15 | ↓3 = $modifier; 16 | } else if ($type == color) { 17 | ↓4 = $modifier; 18 | } else if ($type == origin) { 19 | ↓5 = $modifier; 20 | } else if ($type == material) { 21 | ↓6 = $modifier; 22 | } else if ($type == purpose) { 23 | ↓7 = $modifier; 24 | } else { 25 | ↓8 = $modifier; 26 | } 27 | } 28 | } 29 | attest (↓1 => #1); 30 | attest (↓2 => #2); 31 | attest (↓3 => #3); 32 | attest (↓4 => #4); 33 | attest (↓5 => #5); 34 | attest (↓6 => #6); 35 | attest (↓7 => #7); 36 | attest (↓8 => #8); 37 | } 38 | 39 | @trace 40 | ADJ → adj 41 | { 42 | ↓1 = ↑; 43 | ⇑ = ⇓1; 44 | } 45 | -------------------------------------------------------------------------------- /src/memoization-value.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_MEMOIZATIONVALUE_H 21 | #define ELVEX_MEMOIZATIONVALUE_H 22 | 23 | #include "shared_ptr.hpp" 24 | 25 | class MemoizationValue 26 | { 27 | 28 | private: 29 | featuresPtr features; 30 | 31 | class ForestIdentifier *forestIdentifier; 32 | 33 | MemoizationValue(featuresPtr, class ForestIdentifier *); 34 | 35 | public: 36 | ~MemoizationValue(); 37 | 38 | static class MemoizationValue *create(featuresPtr, class ForestIdentifier *); 39 | 40 | featuresPtr getFeatures(void) const; 41 | 42 | class ForestIdentifier *getForestIdentifier(void) const; 43 | }; 44 | 45 | #endif // ELVEX_MEMOIZATIONVALUE_H 46 | -------------------------------------------------------------------------------- /src/compacted-lexicon-info.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef COMPACTEDLEXICONINFO_H 21 | #define COMPACTEDLEXICONINFO_H 22 | 23 | #include 24 | 25 | class CompactedLexiconInfo 26 | { 27 | private: 28 | class CompactedLexiconInfo *next; 29 | 30 | uint32_t offset; 31 | 32 | uint32_t address; 33 | 34 | public: 35 | CompactedLexiconInfo(class CompactedLexiconInfo *next = nullptr, uint32_t offset = 0); 36 | 37 | ~CompactedLexiconInfo(); 38 | 39 | class CompactedLexiconInfo *getNext(void) const; 40 | 41 | uint32_t getOffset(void) const; 42 | 43 | uint32_t getAddress(void) const; 44 | 45 | void setAddress(uint32_t); 46 | }; 47 | 48 | #endif // COMPACTEDLEXICONINFO_H 49 | -------------------------------------------------------------------------------- /src/fatal_exception.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include "fatal_exception.hpp" 21 | 22 | /* ************************************************** 23 | * 24 | ************************************************** */ 25 | fatal_exception::fatal_exception(std::string message) 26 | : message(std::move(message)) 27 | {} 28 | 29 | /* ************************************************** 30 | * 31 | ************************************************** */ 32 | fatal_exception::fatal_exception(std::ostringstream &oss) 33 | : message(oss.str()) 34 | {} 35 | 36 | /* ************************************************** 37 | * 38 | ************************************************** */ 39 | const char* fatal_exception::what() const noexcept 40 | { 41 | return message.c_str(); 42 | } 43 | -------------------------------------------------------------------------------- /src/memoization-map.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_MEMOIZATIONMAP_H 21 | #define ELVEX_MEMOIZATIONMAP_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "memoization-value.hpp" 27 | 28 | class MemoizationMap : public std::enable_shared_from_this 29 | { 30 | 31 | public: 32 | typedef std::unordered_map> map; 33 | 34 | private: 35 | map memoizationMap; 36 | 37 | public: 38 | void clear(void); 39 | 40 | map::const_iterator cend(void) const; 41 | 42 | map::const_iterator find(const std::string &) const; 43 | 44 | void insert(const std::string &, featuresPtr, class ForestIdentifier *); 45 | }; 46 | 47 | #endif // ELVEX_MEMOIZATIONMAP_H 48 | -------------------------------------------------------------------------------- /src/variableflag.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include "variableflag.hpp" 21 | #include "messages.hpp" 22 | 23 | /* ************************************************** 24 | * 25 | ************************************************** */ 26 | VariableFlag::VariableFlag() noexcept 27 | { 28 | NEW; 29 | flag = NONE; 30 | } 31 | 32 | /* ************************************************** 33 | * 34 | ************************************************** */ 35 | void VariableFlag::setFlag(enum flagValues _flag) 36 | { 37 | this->flag = _flag; 38 | } 39 | 40 | /* ************************************************** 41 | * 42 | ************************************************** */ 43 | bool VariableFlag::containsVariable() 44 | { 45 | if (flag != 0) 46 | return (flag == 1); 47 | return false; 48 | } 49 | -------------------------------------------------------------------------------- /test/test-Foreach.rules: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * Start 3 | ************************************************** */ 4 | @trace 5 | S → adj n adj 6 | { 7 | printlnstderr __FILE__, "..."; 8 | [HEAD:_]; 9 | ↓2 = ↑; 10 | deferred (⇓2) { 11 | [mod:$list, number:$inheritedNumber] ⊂ ↑; 12 | [gender:$synthesizedGender, number:$synthesizedNumber] ⊂ ⇓2; 13 | foreach $i in $list { 14 | println "$i: ", $i; 15 | <$lexiconHead::$lexiconTail> = search $i on adj; 16 | println "$lexiconHead: ", $lexiconHead; 17 | [pos:$posSynthesized] ⊂ $lexiconHead; 18 | [pos:$posInherited] ⊂ $i; 19 | println "$posSynthesized: ", $posSynthesized; 20 | deferred($posSynthesized){ 21 | if ($posInherited){ 22 | $pos = $posInherited; 23 | } 24 | else if ($posSynthesized) { 25 | $pos = $posSynthesized; 26 | } 27 | else { 28 | $pos = none; 29 | } 30 | if ($pos == pre){ 31 | ↓1 = $i U [gender:$synthesizedGender, number:$inheritedNumber] U [number:$synthesizedNumber]; 32 | } 33 | else if ($pos == post){ 34 | ↓3 = $i U [gender:$synthesizedGender, number:$inheritedNumber] U [number:$synthesizedNumber]; 35 | } 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/compacted-lexicon-fsa.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef COMPACTEDLEXICONFSA_H 21 | #define COMPACTEDLEXICONFSA_H 22 | 23 | #include 24 | 25 | struct CompactedLexiconFsa 26 | { 27 | private: 28 | uint32_t child; 29 | uint32_t next; 30 | uint32_t info; 31 | char character; 32 | 33 | public: 34 | CompactedLexiconFsa(uint32_t, uint32_t, uint32_t, char); 35 | 36 | CompactedLexiconFsa(); 37 | 38 | void print(std::ostream &) const; 39 | 40 | bool hasChild() const; 41 | 42 | bool hasInfo() const; 43 | 44 | bool hasNext() const; 45 | 46 | uint32_t getChild(void) const; 47 | 48 | uint32_t getNext(void) const; 49 | 50 | uint32_t getInfo(void) const; 51 | 52 | bool equalsThisChar(char character) const; 53 | 54 | char getCharacter() const { return character; } 55 | }; 56 | 57 | #endif // COMPACTEDLEXICONFSA_H 58 | -------------------------------------------------------------------------------- /src/uniq-id.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include "uniq-id.hpp" 21 | #include 22 | #include 23 | 24 | std::uint32_t UniqId::uniqId = 1; 25 | 26 | /* ************************************************** 27 | * 28 | ************************************************** */ 29 | UniqId::UniqId(uint32_t id) 30 | { 31 | if (id) 32 | this->id = id; 33 | else 34 | this->id = ++uniqId; 35 | } 36 | 37 | /* ************************************************** 38 | * 39 | ************************************************** */ 40 | std::uint32_t UniqId::getId() const 41 | { 42 | return this->id; 43 | } 44 | 45 | /* ************************************************** 46 | * 47 | ************************************************** */ 48 | std::string UniqId::getIdStr() const 49 | { 50 | std::stringstream ss; 51 | ss << std::hex << this->id; 52 | return ss.str(); 53 | } 54 | -------------------------------------------------------------------------------- /src/forestmap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_FORESTMAP_H 21 | #define ELVEX_FORESTMAP_H 22 | 23 | #include 24 | #include "shared_ptr.hpp" 25 | #include "forestidentifier.hpp" 26 | 27 | class ForestMap { 28 | 29 | public: 30 | typedef std::unordered_map map; 34 | 35 | 36 | private: 37 | map data; 38 | 39 | public: 40 | ForestMap(); 41 | 42 | ~ForestMap(); 43 | 44 | map::const_iterator find(class ForestIdentifier*) const; 45 | 46 | map::const_iterator cbegin() const; 47 | 48 | map::const_iterator cend() const; 49 | 50 | void clear(); 51 | 52 | bool insert(class ForestIdentifier*, forestPtr); 53 | 54 | }; 55 | 56 | #endif // ELVEX_FORESTMAP_H 57 | -------------------------------------------------------------------------------- /src/facade.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_FACADE_H 21 | #define ELVEX_FACADE_H 22 | 23 | #include "flags.hpp" 24 | #include "uniq-id.hpp" 25 | #include "shared_ptr.hpp" 26 | #include "serializable.hpp" 27 | #include "variableflag.hpp" 28 | 29 | #ifdef OUTPUT_XML 30 | #include 31 | #endif 32 | 33 | class Facade 34 | { 35 | 36 | private: 37 | UniqId uniqId; 38 | Flags flags; 39 | 40 | public: 41 | Facade(std::size_t id = 0, const std::bitset &flags = 0); 42 | 43 | ~Facade(); 44 | 45 | std::bitset &getFlags(); 46 | 47 | bool isSetFlags(const std::bitset &cmp) const; 48 | 49 | bool isUnsetFlags(const std::bitset &cmp) const; 50 | 51 | void addFlags(const std::bitset &f); 52 | 53 | void subFlags(const std::bitset &f); 54 | 55 | void printFlags(std::ostream &) const; 56 | 57 | std::uint32_t getId(void) const; 58 | 59 | std::string getIdStr(void) const; 60 | }; 61 | 62 | #endif // ELVEX_FACADE_H 63 | -------------------------------------------------------------------------------- /src/compacted-lexicon-tree.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef COMPACTEDLEXICONTREE_H 21 | #define COMPACTEDLEXICONTREE_H 22 | 23 | #include 24 | 25 | class CompactedLexiconTree 26 | { 27 | 28 | private: 29 | CompactedLexiconTree *child; 30 | CompactedLexiconTree *next; 31 | class CompactedLexiconInfo *info; 32 | 33 | char character; 34 | uint32_t address; 35 | 36 | public: 37 | CompactedLexiconTree(CompactedLexiconTree *child, CompactedLexiconTree *sibling, class CompactedLexiconInfo *info, 38 | const char character); 39 | 40 | ~CompactedLexiconTree(); 41 | 42 | void setChild(CompactedLexiconTree *); 43 | 44 | CompactedLexiconTree *getChild() const; 45 | 46 | void add(const char *, uint32_t); 47 | 48 | void setIndexStaticFSA(uint32_t &); 49 | 50 | void printStaticFSA(FILE *, class CompactedLexicon *) const; 51 | 52 | void setIndexStaticInfo(uint32_t &); 53 | 54 | void printStaticInfo(FILE *) const; 55 | }; 56 | 57 | #endif // COMPACTEDLEXICONTREE_H 58 | -------------------------------------------------------------------------------- /src/shared_ptr.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_SHARED_PTR_H 21 | #define ELVEX_SHARED_PTR_H 22 | 23 | #include 24 | 25 | typedef std::shared_ptr bitsetPtr; 26 | typedef std::shared_ptr entriesPtr; 27 | typedef std::shared_ptr entryPtr; 28 | typedef std::shared_ptr environmentPtr; 29 | typedef std::shared_ptr featurePtr; 30 | typedef std::shared_ptr featuresPtr; 31 | typedef std::shared_ptr forestPtr; 32 | typedef std::shared_ptr pairpPtr; 33 | typedef std::shared_ptr listFeaturesPtr; 34 | typedef std::shared_ptr nodePtr; 35 | typedef std::shared_ptr rulePtr; 36 | typedef std::shared_ptr statementPtr; 37 | typedef std::shared_ptr statementsPtr; 38 | typedef std::shared_ptr terminalPtr; 39 | typedef std::shared_ptr termsPtr; 40 | typedef std::shared_ptr valuePtr; 41 | 42 | #endif // ELVEX_SHARED_PTR_H 43 | -------------------------------------------------------------------------------- /test/test-InheritedSynthesized.lexicon: -------------------------------------------------------------------------------- 1 | "." dot; 2 | "---$val1---$val2---$val3---" tag[attr1:$val1, attr2:$val2, attr3:$val3]; 3 | FORM adjForm [att1:val1, att2: val2]; 4 | FORM nounForm [att3:val3, att4: val4]; 5 | 6 | le det[@ms]; 7 | la det[@fs]; 8 | les det[@p]; 9 | 10 | "un certain nombre de" det[@p]; 11 | 12 | ce det[@ms]; 13 | cette det[@f]; 14 | ces det[@p]; 15 | 16 | mon det[@ms]; 17 | ma det[@fs]; 18 | mes det[@p]; 19 | 20 | chat noun[HEAD:CHAT,@ms]; 21 | chatte noun[HEAD:CHAT,@fs]; 22 | chats noun[HEAD:CHAT,@mp]; 23 | chattes noun[HEAD:CHAT,@fp]; 24 | chien noun[HEAD:CHIEN,@ms]; 25 | chienne noun[HEAD:CHIEN,@fs]; 26 | chiens noun[HEAD:CHIEN,@mp]; 27 | chiennes noun[HEAD:CHIEN,@fp]; 28 | poule noun[HEAD:POULE,@fs]; 29 | poulet noun[HEAD:POULE,@ms]; 30 | poules noun[HEAD:POULE,@fp]; 31 | poulets noun[HEAD:POULE,@mp]; 32 | renard noun[HEAD:RENARD, @ms]; 33 | renarde noun[HEAD:RENARD, @fs]; 34 | renards noun[HEAD:RENARD, @mp]; 35 | renardes noun[HEAD:RENARD, @fp]; 36 | souris noun[HEAD:SOURIS, @f]; 37 | 38 | "chauve souris (in cache lexicon)" noun[HEAD:CHAUVE_SOURIS, cache:true, @fs]; 39 | "chauves souris (in cache lexicon)" noun[HEAD:CHAUVE_SOURIS, cache:true, @fp]; 40 | 41 | belle adj[HEAD:BEAU,@fs]; 42 | beau adj[HEAD:BEAU,@ms]; 43 | belles adj[HEAD:BEAU,@fp]; 44 | beaux adj[HEAD:BEAU,@mp]; 45 | gentille adj[HEAD:GENTIL,@fs]; 46 | gentil adj[HEAD:GENTIL,@ms]; 47 | gentilles adj[HEAD:GENTIL,@fp]; 48 | gentils adj[HEAD:GENTIL,@mp]; 49 | vieux adj[HEAD:VIEUX,@m]; 50 | vieille adj[HEAD:VIEUX,@fs]; 51 | vieilles adj[HEAD:VIEUX,@fp]; 52 | 53 | -------------------------------------------------------------------------------- /test/test-Foreach.test: -------------------------------------------------------------------------------- 1 | $i: [HEAD:BEAU] 2 | $lexiconHead: [HEAD:BEAU, gender:fm, number:pl, pos:pre, form:"belles"] 3 | $posSynthesized: pre 4 | $i: [HEAD:JAUNE] 5 | $lexiconHead: [HEAD:JAUNE, number:pl, pos:post, form:"jaunes"] 6 | $posSynthesized: post 7 | $i: [HEAD:BEAU] 8 | $lexiconHead: [HEAD:BEAU, gender:fm, number:pl, pos:pre, form:"belles"] 9 | $posSynthesized: pre 10 | $i: [HEAD:JAUNE] 11 | $lexiconHead: [HEAD:JAUNE, number:pl, pos:post, form:"jaunes"] 12 | $posSynthesized: post 13 | $i: [HEAD:BEAU] 14 | $lexiconHead: [HEAD:BEAU, gender:fm, number:pl, pos:pre, form:"belles"] 15 | $posSynthesized: pre 16 | $i: [HEAD:JAUNE] 17 | $lexiconHead: [HEAD:JAUNE, number:pl, pos:post, form:"jaunes"] 18 | $posSynthesized: post 19 | $i: [HEAD:BEAU] 20 | $lexiconHead: [HEAD:BEAU, gender:fm, number:pl, pos:pre, form:"belles"] 21 | $posSynthesized: pre 22 | $i: [HEAD:JAUNE] 23 | $lexiconHead: [HEAD:JAUNE, number:pl, pos:post, form:"jaunes"] 24 | $posSynthesized: post 25 | $i: [HEAD:BEAU] 26 | $lexiconHead: [HEAD:BEAU, gender:fm, number:pl, pos:pre, form:"belles"] 27 | $posSynthesized: pre 28 | $i: [HEAD:JAUNE] 29 | $lexiconHead: [HEAD:JAUNE, number:pl, pos:post, form:"jaunes"] 30 | $posSynthesized: post 31 | $i: [HEAD:BEAU] 32 | $lexiconHead: [HEAD:BEAU, gender:fm, number:pl, pos:pre, form:"belles"] 33 | $posSynthesized: pre 34 | $i: [HEAD:JAUNE] 35 | $lexiconHead: [HEAD:JAUNE, number:pl, pos:post, form:"jaunes"] 36 | $posSynthesized: post 37 | belle voiture jaune 38 | beau véhicule jaune 39 | beaux véhicules jaunes 40 | belles bagnoles jaunes 41 | belles voitures jaunes 42 | belle bagnole jaune 43 | -------------------------------------------------------------------------------- /test/test-InheritedSynthesized.test: -------------------------------------------------------------------------------- 1 | un certain nombre de (this is an input form value4) chauves souris . ---56------ value4 ------a|b--- 2 | ces (this is an input form value4) chauves souris . ---56------ value4 ------a|b--- 3 | cette (this is an input form value4) chauves souris (in cache lexicon) . ---56------ value4 ------a|b--- 4 | cette (this is an input form value4) chauve souris (in cache lexicon) . ---56------ value4 ------a|b--- 5 | ma (this is an input form value4) chauve souris . ---56------ value4 ------a|b--- 6 | ces (this is an input form value4) chauves souris (in cache lexicon) . ---56------ value4 ------a|b--- 7 | les (this is an input form value4) chauves souris (in cache lexicon) . ---56------ value4 ------a|b--- 8 | ma (this is an input form value4) chauve souris (in cache lexicon) . ---56------ value4 ------a|b--- 9 | la (this is an input form value4) chauve souris . ---56------ value4 ------a|b--- 10 | mes (this is an input form value4) chauves souris (in cache lexicon) . ---56------ value4 ------a|b--- 11 | un certain nombre de (this is an input form value4) chauves souris (in cache lexicon) . ---56------ value4 ------a|b--- 12 | les (this is an input form value4) chauves souris . ---56------ value4 ------a|b--- 13 | mes (this is an input form value4) chauves souris . ---56------ value4 ------a|b--- 14 | cette (this is an input form value4) chauve souris . ---56------ value4 ------a|b--- 15 | cette (this is an input form value4) chauves souris . ---56------ value4 ------a|b--- 16 | la (this is an input form value4) chauve souris (in cache lexicon) . ---56------ value4 ------a|b--- 17 | -------------------------------------------------------------------------------- /src/bitset.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef BITSET_H 21 | #define BITSET_H 22 | 23 | #include 24 | #include 25 | 26 | #include "shared_ptr.hpp" 27 | #include "serializable.hpp" 28 | 29 | #ifdef OUTPUT_XML 30 | #include 31 | #endif 32 | 33 | #ifndef MAXBITS 34 | #define MAXBITS 512 35 | #endif 36 | 37 | class Bitset : public std::bitset, 38 | public Serializable, 39 | public std::enable_shared_from_this 40 | { 41 | 42 | private: 43 | void makeSerialString() override; 44 | 45 | public: 46 | explicit Bitset(unsigned int = 0); 47 | 48 | explicit Bitset(const std::bitset &); 49 | 50 | explicit Bitset(const bitsetPtr &); 51 | 52 | ~Bitset() override; 53 | 54 | static bitsetPtr create(unsigned int = 0); 55 | 56 | static bitsetPtr create(const std::bitset); 57 | 58 | static bitsetPtr create(const bitsetPtr &); 59 | 60 | std::string toString() const; 61 | 62 | #ifdef OUTPUT_XML 63 | void toXML(xmlNodePtr); 64 | #endif 65 | 66 | bitsetPtr clone(void); 67 | }; 68 | 69 | #endif // BITSET_H 70 | -------------------------------------------------------------------------------- /src/flags.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_FLAGS_H 21 | #define ELVEX_FLAGS_H 22 | 23 | #include 24 | 25 | #define MAX_FLAGS 8 26 | 27 | class Flags 28 | { 29 | 30 | public: 31 | static const std::bitset SEEN; 32 | static const std::bitset XML; 33 | static const std::bitset GENERATED; 34 | static const std::bitset DISABLED; 35 | static const std::bitset NIL; 36 | static const std::bitset BOTTOM; 37 | static const std::bitset REJECTED; 38 | static const std::bitset CHOOSEN; 39 | 40 | private: 41 | std::bitset flags; 42 | 43 | public: 44 | Flags(); 45 | 46 | explicit Flags(const std::bitset &flags); 47 | 48 | std::bitset &getFlags(); 49 | 50 | bool isSet(const std::bitset &cmp) const; 51 | 52 | bool isUnset(const std::bitset &cmp) const; 53 | 54 | void add(const std::bitset &f); 55 | 56 | void sub(const std::bitset &f); 57 | 58 | void print(std::ostream &) const; 59 | }; 60 | 61 | #endif // ELVEX_FLAGS_H 62 | -------------------------------------------------------------------------------- /src/forestidentifier.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_FORESTIDENTIFIER_H 21 | #define ELVEX_FORESTIDENTIFIER_H 22 | 23 | #include "serializable.hpp" 24 | #include "shared_ptr.hpp" 25 | 26 | class ForestIdentifier : 27 | public Serializable { 28 | 29 | private: 30 | 31 | uint32_t code; 32 | uint32_t from; 33 | uint32_t to; 34 | 35 | 36 | public: 37 | ForestIdentifier(uint32_t code, uint32_t from, uint32_t to); 38 | 39 | ~ForestIdentifier() override; 40 | 41 | static class ForestIdentifier* create(uint32_t code, uint32_t from, uint32_t to); 42 | 43 | void makeSerialString() override; 44 | 45 | uint32_t getFrom() const { 46 | return from; 47 | }; 48 | 49 | uint32_t getTo() const { 50 | return to; 51 | }; 52 | 53 | uint32_t getCode() const { 54 | return code; 55 | }; 56 | 57 | struct Hash { 58 | size_t operator()(class ForestIdentifier *) const; 59 | }; 60 | 61 | struct KeyEqual { 62 | bool operator()(class ForestIdentifier *, class ForestIdentifier *) const; 63 | }; 64 | 65 | }; 66 | 67 | #endif // ELVEX_FORESTIDENTIFIER_H 68 | -------------------------------------------------------------------------------- /src/entry.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_ENTRY_H 21 | #define ELVEX_ENTRY_H 22 | 23 | #include "facade.hpp" 24 | #include "serializable.hpp" 25 | #include "shared_ptr.hpp" 26 | 27 | #ifdef OUTPUT_XML 28 | #include 29 | #endif 30 | 31 | class Entry : public Facade, 32 | public Serializable, 33 | public std::enable_shared_from_this 34 | { 35 | 36 | private: 37 | 38 | std::string form; 39 | 40 | featuresPtr features; 41 | 42 | void makeSerialString(void); 43 | 44 | public: 45 | Entry(const std::string &form, featuresPtr features); 46 | 47 | Entry(featuresPtr features); 48 | 49 | ~Entry(); 50 | 51 | static entryPtr create(const std::string &form, featuresPtr features); 52 | 53 | static entryPtr create(featuresPtr features); 54 | 55 | std::string &getForm(); 56 | 57 | featuresPtr getFeatures() const; 58 | 59 | #ifdef OUTPUT_XML 60 | void toXML(xmlNodePtr nodeRoot) const; 61 | #endif 62 | 63 | void print(std::ostream &) const; 64 | 65 | void renameVariables(uint32_t); 66 | 67 | entryPtr clone(void) const; 68 | 69 | }; 70 | 71 | #endif // ELVEX_ENTRY_H 72 | -------------------------------------------------------------------------------- /src/lexicon.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_LEXICON_H 21 | #define ELVEX_LEXICON_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | class Lexicon 28 | { 29 | 30 | public: 31 | typedef std::unordered_map, 33 | std::hash, 34 | std::equal_to, 35 | std::allocator > > > 36 | unordered_map; 37 | 38 | private: 39 | std::string name; 40 | 41 | unordered_map the_map; 42 | 43 | static std::vector emptyList; 44 | 45 | public: 46 | Lexicon(std::string name); 47 | 48 | unordered_map::const_iterator cbegin(void); 49 | 50 | unordered_map::const_iterator cend(void); 51 | 52 | std::size_t size(void); 53 | 54 | void add(std::string key, std::string value); 55 | 56 | std::vector find(std::string key); 57 | 58 | std::size_t count(std::string key); 59 | 60 | std::string &toString(void) const; 61 | }; 62 | 63 | #endif // ELVEX_LEXICON_H 64 | -------------------------------------------------------------------------------- /src/entries.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ENTRIES_H 21 | #define ENTRIES_H 22 | 23 | #ifdef OUTPUT_XML 24 | #include 25 | #endif 26 | 27 | #include 28 | #include "shared_ptr.hpp" 29 | 30 | class Entries : public std::enable_shared_from_this 31 | { 32 | 33 | private: 34 | std::vector entries; 35 | 36 | public: 37 | Entries(); 38 | 39 | Entries(const entryPtr &); 40 | 41 | Entries(const std::vector &); 42 | 43 | ~Entries(); 44 | 45 | static entriesPtr create(); 46 | 47 | static entriesPtr create(const entryPtr &); 48 | 49 | static entriesPtr create(const std::vector &); 50 | 51 | size_t size() const; 52 | 53 | std::vector::const_iterator cbegin() const; 54 | 55 | std::vector::const_iterator cend() const; 56 | 57 | std::vector::iterator begin(); 58 | 59 | std::vector::iterator end(); 60 | 61 | entryPtr get(unsigned int) const; 62 | 63 | void add(const entryPtr &); 64 | 65 | void add(entriesPtr); 66 | 67 | #ifdef OUTPUT_XML 68 | void toXML(xmlNodePtr) const; 69 | #endif 70 | 71 | void print(std::ostream &) const; 72 | }; 73 | 74 | #endif // ENTRIES_H 75 | -------------------------------------------------------------------------------- /src/forest.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_FOREST_H 21 | #define ELVEX_FOREST_H 22 | 23 | #include 24 | #include 25 | #include "facade.hpp" 26 | 27 | #ifdef OUTPUT_XML 28 | #include 29 | #endif 30 | 31 | #include "flags.hpp" 32 | #include "shared_ptr.hpp" 33 | 34 | class Forest : public Facade, 35 | public std::enable_shared_from_this 36 | { 37 | 38 | public: 39 | typedef std::vector vectorNodes; 40 | 41 | private: 42 | static std::string EMPTY_FORM; 43 | uint32_t from; 44 | uint32_t to; 45 | vectorNodes nodes; 46 | bool empty; 47 | std::forward_list output; 48 | std::string form; 49 | 50 | public: 51 | Forest(uint32_t from, uint32_t to, std::string &form); 52 | 53 | ~Forest(); 54 | 55 | static forestPtr create(uint32_t from, uint32_t to, std::string &form = EMPTY_FORM); 56 | 57 | uint32_t getFrom(void) const; 58 | 59 | uint32_t getTo(void) const; 60 | 61 | bool output_empty(void) const; 62 | 63 | const std::forward_list::const_iterator output_cbegin(void) const; 64 | 65 | const std::forward_list::const_iterator output_cend(void) const; 66 | 67 | void push_node(const nodePtr &); 68 | 69 | void push_output(std::string output); 70 | 71 | std::string &getForm(void); 72 | 73 | 74 | #ifdef OUTPUT_XML 75 | void toXML(const xmlNodePtr, bool); 76 | #endif 77 | 78 | void generate(bool randomResult, bool singleResult); 79 | }; 80 | 81 | #endif // ELVEX_FOREST_H 82 | -------------------------------------------------------------------------------- /src/itemset.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_ITEMSET_H 21 | #define ELVEX_ITEMSET_H 22 | 23 | #include 24 | 25 | #ifdef OUTPUT_XML 26 | #include 27 | #endif 28 | 29 | #include "item.hpp" 30 | #include "shared_ptr.hpp" 31 | 32 | class ItemSet 33 | { 34 | 35 | public: 36 | typedef std::unordered_set> 40 | set_of_item; 41 | typedef set_of_item::const_iterator set_of_item_const_iterator; 42 | typedef set_of_item::iterator set_of_item_iterator; 43 | 44 | private: 45 | unsigned int id; 46 | 47 | set_of_item items; 48 | 49 | public: 50 | ItemSet(unsigned int); 51 | 52 | ~ItemSet(); 53 | 54 | static class ItemSet *create(unsigned int); 55 | 56 | unsigned int getId(void); 57 | 58 | set_of_item &getItems(void); 59 | 60 | set_of_item_const_iterator cbegin(void) const; 61 | 62 | set_of_item_const_iterator cend(void) const; 63 | 64 | set_of_item_iterator begin(void); 65 | 66 | set_of_item_iterator end(void); 67 | 68 | set_of_item_const_iterator find(class Item *) const; 69 | 70 | bool insert(class Item *, class Generator *); 71 | 72 | void erase(class Item *); 73 | 74 | size_t size(void) const; 75 | 76 | void resetUsages(void); 77 | 78 | void print(std::ostream &); 79 | 80 | #ifdef OUTPUT_XML 81 | void toXML(xmlNodePtr); 82 | #endif 83 | }; 84 | 85 | #endif // ITEM_H 86 | -------------------------------------------------------------------------------- /src/listfeatures.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_LISTFEATURES_H 21 | #define ELVEX_LISTFEATURES_H 22 | 23 | #include 24 | #include "shared_ptr.hpp" 25 | #include "facade.hpp" 26 | 27 | class ListFeatures : public Facade, 28 | public Serializable, 29 | public std::enable_shared_from_this 30 | { 31 | 32 | private: 33 | std::vector listFeatures; 34 | 35 | void makeSerialString(); 36 | 37 | public: 38 | ListFeatures(void); 39 | 40 | ~ListFeatures(); 41 | 42 | static listFeaturesPtr create(void); 43 | 44 | void push_back(const featuresPtr &); 45 | 46 | void add(unsigned int, featuresPtr); 47 | 48 | featuresPtr get(unsigned int); 49 | 50 | void clear(void); 51 | 52 | std::vector::const_iterator cbegin() const; 53 | 54 | std::vector::const_iterator cend() const; 55 | 56 | std::vector::iterator begin() ; 57 | 58 | std::vector::iterator end() ; 59 | 60 | size_t size() const; 61 | 62 | listFeaturesPtr clone(void); 63 | 64 | featuresPtr operator[](unsigned int); 65 | 66 | void print(std::ostream &) const; 67 | 68 | void flatPrint(std::ostream &) const; 69 | 70 | void apply(statementPtr from, class Item *item, class Parser &parser, class Generator *synthesizer, const statementPtr &variable, statementPtr body, 71 | bool &effect, bool verbose); 72 | 73 | #ifdef OUTPUT_XML 74 | void toXML(xmlNodePtr); 75 | #endif 76 | 77 | }; 78 | 79 | #endif // ELVEX_LISTFEATURES_H 80 | -------------------------------------------------------------------------------- /src/memoization-value.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include "memoization-value.hpp" 21 | 22 | #include 23 | #include "messages.hpp" 24 | 25 | /* ************************************************************ 26 | * 27 | ************************************************************ */ 28 | MemoizationValue::MemoizationValue(featuresPtr features, class ForestIdentifier *forestIdentifier) 29 | { 30 | NEW; 31 | this->features = features; 32 | this->forestIdentifier = std::move(forestIdentifier); 33 | } 34 | 35 | /* ************************************************************ 36 | * 37 | ************************************************************ */ 38 | MemoizationValue::~MemoizationValue() 39 | { 40 | DELETE; 41 | } 42 | 43 | /* ************************************************************ 44 | * 45 | ************************************************************ */ 46 | class MemoizationValue *MemoizationValue::create(featuresPtr features, class ForestIdentifier *forestIdentifier) 47 | { 48 | return new MemoizationValue(features, std::move(forestIdentifier)); 49 | } 50 | 51 | /* ************************************************************ 52 | * 53 | ************************************************************ */ 54 | featuresPtr MemoizationValue::getFeatures() const 55 | { 56 | return this->features; 57 | } 58 | 59 | /* ************************************************************ 60 | * 61 | ************************************************************ */ 62 | class ForestIdentifier *MemoizationValue::getForestIdentifier() const 63 | { 64 | return this->forestIdentifier; 65 | } 66 | -------------------------------------------------------------------------------- /src/rules.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_RULES_H 21 | #define ELVEX_RULES_H 22 | 23 | #include 24 | #include 25 | #include "shared_ptr.hpp" 26 | 27 | #ifdef OUTPUT_XML 28 | #include 29 | #endif 30 | 31 | class Rules 32 | { 33 | public: 34 | typedef std::list list_of_rule; 35 | typedef std::unordered_set set_of_uint32_t; 36 | 37 | private: 38 | set_of_uint32_t terminals; 39 | set_of_uint32_t nonTerminals; 40 | list_of_rule rules; 41 | uint32_t startTerm; 42 | rulePtr firstRule; 43 | uint32_t idMax; 44 | 45 | public: 46 | Rules(void); 47 | 48 | ~Rules(void); 49 | 50 | set_of_uint32_t &getTerminals(void); 51 | 52 | set_of_uint32_t &getNonTerminals(void); 53 | 54 | const list_of_rule &getRules(void) const; 55 | 56 | uint32_t getStartTerm(void) const; 57 | 58 | rulePtr getFirstRule(void) const; 59 | 60 | const uint32_t *getRefIdMax(void) const; 61 | 62 | void setStartTerm(uint32_t startTerm); 63 | 64 | list_of_rule::const_iterator cbegin(void) const; 65 | 66 | list_of_rule::const_iterator cend(void) const; 67 | 68 | void addRule(rulePtr); 69 | 70 | void addNonTerminal(uint32_t); 71 | 72 | void addTerminal(uint32_t); 73 | 74 | void print(std::ostream &) const; 75 | 76 | bool isTerminal(uint32_t) const; 77 | 78 | bool isNonTerminal(uint32_t) const; 79 | 80 | void analyseTerms(class Parser &); 81 | 82 | #ifdef OUTPUT_XML 83 | void toXML(xmlNodePtr); 84 | #endif 85 | 86 | list_of_rule *findRules(uint32_t lhs); 87 | }; 88 | 89 | #endif // ELVEX_RULES_H 90 | -------------------------------------------------------------------------------- /doc/doc-en.out: -------------------------------------------------------------------------------- 1 | \BOOKMARK [1][-]{section.1}{\376\377\000G\000r\000a\000m\000m\000a\000r\000\040\000b\000y\000\040\000s\000a\000m\000p\000l\000e}{}% 1 2 | \BOOKMARK [2][-]{subsection.1.1}{\376\377\000S\000y\000n\000t\000a\000g\000m\000a\000t\000i\000c\000\040\000d\000e\000s\000c\000r\000i\000p\000t\000i\000o\000n\000\040\000\050\000C\000o\000n\000t\000e\000x\000t\000-\000F\000r\000e\000e\000\040\000G\000r\000a\000m\000m\000a\000r\000\040\000r\000u\000l\000e\000s\000\051}{section.1}% 2 3 | \BOOKMARK [2][-]{subsection.1.2}{\376\377\000O\000p\000e\000r\000a\000t\000i\000o\000n\000a\000l\000\040\000s\000e\000m\000a\000n\000t\000i\000c\000s}{section.1}% 3 4 | \BOOKMARK [1][-]{section.2}{\376\377\000E\000l\000v\000e\000x\000\040\000n\000o\000t\000a\000t\000i\000o\000n\000s}{}% 4 5 | \BOOKMARK [2][-]{subsection.2.1}{\376\377\000O\000p\000e\000r\000a\000t\000i\000o\000n\000a\000l\000\040\000S\000e\000m\000a\000n\000t\000i\000c\000s}{section.2}% 5 6 | \BOOKMARK [2][-]{subsection.2.2}{\376\377\000L\000e\000x\000i\000c\000o\000n}{section.2}% 6 7 | \BOOKMARK [2][-]{subsection.2.3}{\376\377\000I\000n\000p\000u\000t}{section.2}% 7 8 | \BOOKMARK [1][-]{section.3}{\376\377\000D\000e\000s\000i\000g\000n\000\040\000p\000a\000t\000t\000e\000r\000n\000\040\000\050\000t\000o\000\040\000b\000e\000\040\000c\000o\000m\000p\000l\000e\000t\000e\000d\000\051}{}% 8 9 | \BOOKMARK [1][-]{section.4}{\376\377\000T\000h\000e\000\040\000e\000l\000v\000e\000x\000\040\000c\000o\000m\000m\000a\000n\000d}{}% 9 10 | \BOOKMARK [2][-]{subsubsection.4.0.1}{\376\377\000t\000r\000y\000\040\000E\000l\000v\000e\000x}{section.4}% 10 11 | \BOOKMARK [2][-]{subsection.4.1}{\376\377\000E\000l\000v\000e\000x\000\040\000c\000o\000m\000m\000a\000n\000d}{section.4}% 11 12 | \BOOKMARK [2][-]{subsection.4.2}{\376\377\000G\000r\000a\000m\000m\000a\000r\000\040\000d\000e\000b\000u\000g\000g\000i\000n\000g}{section.4}% 12 13 | \BOOKMARK [2][-]{subsection.4.3}{\376\377\000e\000l\000v\000e\000x\000b\000u\000i\000l\000d\000l\000e\000x\000i\000c\000o\000n\000\040\000f\000o\000r\000\040\000m\000a\000n\000a\000g\000i\000n\000g\000\040\000b\000i\000g\000\040\000l\000e\000x\000i\000c\000o\000n\000s}{section.4}% 13 14 | -------------------------------------------------------------------------------- /src/environment.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_ENVIRONMENT_H 21 | #define ELVEX_ENVIRONMENT_H 22 | 23 | #include 24 | #include 25 | #include "shared_ptr.hpp" 26 | 27 | class Environment : public std::enable_shared_from_this 28 | { 29 | 30 | public: 31 | typedef std::unordered_map unordered_map; 32 | 33 | private: 34 | unordered_map env; 35 | 36 | bool add(statementPtr from, const std::string &, valuePtr, bool verbose); 37 | 38 | bool remove(const std::string &); 39 | 40 | public: 41 | Environment(); 42 | 43 | ~Environment(); 44 | 45 | static environmentPtr create(void); 46 | 47 | bool add(statementPtr from, uint32_t, valuePtr, bool verbose); 48 | 49 | bool add(statementPtr from, const environmentPtr &, bool verbose); 50 | 51 | bool add(statementPtr from, const environmentPtr &, const environmentPtr &, bool verbose); 52 | 53 | bool remove(uint32_t); 54 | 55 | unordered_map::const_iterator begin() const; 56 | 57 | unordered_map::const_iterator end() const; 58 | 59 | bool empty() const; 60 | 61 | void print(std::ostream &) const; 62 | 63 | environmentPtr clone(statementPtr from, bool verbose) const; 64 | 65 | valuePtr find(const uint32_t) const; 66 | 67 | void replaceVariables(const valuePtr &, bool &); 68 | 69 | void replaceVariables(const featuresPtr &, bool &); 70 | 71 | //void replaceVariables(const listFeaturesPtr &, bool &); 72 | 73 | void replaceVariables(const pairpPtr &, bool &); 74 | 75 | void replaceVariables(std::string &, bool &); 76 | }; 77 | 78 | #endif // ELVEX_ENVIRONMENT_H 79 | -------------------------------------------------------------------------------- /src/compacted-lexicon-info.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include "compacted-lexicon-info.hpp" 21 | #include "messages.hpp" 22 | 23 | /* ************************************************** 24 | * 25 | ************************************************** */ 26 | CompactedLexiconInfo::CompactedLexiconInfo(class CompactedLexiconInfo *next, uint32_t offset) 27 | { 28 | NEW this->address = 0; 29 | this->next = next; 30 | this->offset = offset; 31 | } 32 | 33 | /* ************************************************** 34 | * 35 | ************************************************** */ 36 | CompactedLexiconInfo::~CompactedLexiconInfo() 37 | { 38 | DELETE 39 | if (next) 40 | { 41 | delete (next); 42 | next = NULL; 43 | } 44 | } 45 | 46 | /* ************************************************** 47 | * 48 | ************************************************** */ 49 | class CompactedLexiconInfo *CompactedLexiconInfo::getNext(void) const 50 | { 51 | return next; 52 | } 53 | 54 | /* ************************************************** 55 | * 56 | ************************************************** */ 57 | uint32_t CompactedLexiconInfo::getOffset(void) const 58 | { 59 | return offset; 60 | } 61 | 62 | /* ************************************************** 63 | * 64 | ************************************************** */ 65 | uint32_t CompactedLexiconInfo::getAddress(void) const 66 | { 67 | return address; 68 | } 69 | 70 | /* ************************************************** 71 | * 72 | ************************************************** */ 73 | void CompactedLexiconInfo::setAddress(uint32_t _address) 74 | { 75 | this->address = _address; 76 | } 77 | -------------------------------------------------------------------------------- /src/serializable.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include 21 | #include "serializable.hpp" 22 | #include "messages.hpp" 23 | 24 | /* ************************************************** 25 | * 26 | ************************************************** */ 27 | Serializable::Serializable() 28 | { 29 | serialString = std::string(); 30 | serialHashCode = 0; 31 | } 32 | 33 | /* ************************************************** 34 | * 35 | ************************************************** */ 36 | Serializable::~Serializable() 37 | { 38 | } 39 | 40 | /* ************************************************** 41 | * 42 | ************************************************** */ 43 | std::string Serializable::peekSerialString() 44 | { 45 | if (serialHashCode == 0) 46 | { 47 | std::string old = serialString; 48 | makeSerialString(); 49 | if (!old.empty() && old != serialString){ 50 | std::cerr << old << " != " << serialString << std::endl; 51 | } 52 | serialHashCode = std::hash{}(serialString); 53 | } 54 | return serialString; 55 | } 56 | 57 | /* ************************************************** 58 | * 59 | ************************************************** */ 60 | void Serializable::resetSerial() 61 | { 62 | serialHashCode = 0; 63 | } 64 | 65 | /* ************************************************** 66 | * 67 | ************************************************** */ 68 | size_t Serializable::hash() 69 | { 70 | if (serialHashCode == 0) 71 | { 72 | makeSerialString(); 73 | return serialHashCode = std::hash{}(serialString); 74 | } 75 | return serialHashCode; 76 | } 77 | -------------------------------------------------------------------------------- /src/terms.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_TERMS_H 21 | #define ELVEX_TERMS_H 22 | 23 | #include 24 | #include 25 | 26 | #ifdef OUTPUT_XML 27 | #include 28 | #endif 29 | 30 | #include "facade.hpp" 31 | #include "shared_ptr.hpp" 32 | 33 | class Terms : 34 | public Facade, 35 | public std::enable_shared_from_this 36 | { 37 | 38 | private: 39 | std::vector terms; 40 | bool optional; 41 | 42 | Terms(std::vector &, bool optional); 43 | 44 | Terms(uint32_t, bool optional); 45 | 46 | Terms(void); 47 | 48 | public: 49 | ~Terms(); 50 | 51 | static termsPtr create(std::vector &, bool optional = false); 52 | 53 | static termsPtr create(uint32_t, bool optional = false); 54 | 55 | static termsPtr create(void); 56 | 57 | bool isOptional(void) const; 58 | 59 | void setOptional(void); 60 | 61 | void unsetOptional(void); 62 | 63 | size_t size(void) const; 64 | 65 | std::vector::const_iterator begin(void) const; 66 | 67 | std::vector::const_iterator end(void) const; 68 | 69 | void erase(std::vector::iterator begin, std::vector::iterator end); 70 | 71 | void push_back(uint32_t term); 72 | 73 | void print(std::ostream &outStream = std::cout); 74 | 75 | termsPtr clone(void) const; 76 | 77 | #ifdef OUTPUT_XML 78 | void toXML(xmlNodePtr); 79 | #endif 80 | 81 | // compares two terms 82 | struct Less 83 | { 84 | bool operator()(const termsPtr t1, const termsPtr t2) const; 85 | }; 86 | 87 | uint32_t operator[](size_t); 88 | }; 89 | 90 | #endif // ELVEX_TERMS_H 91 | -------------------------------------------------------------------------------- /src/postedition_en.l: -------------------------------------------------------------------------------- 1 | %{ 2 | /* ************************************************** 3 | * 4 | * ELVEX 5 | * 6 | * Copyright 2014-2023 LABRI, 7 | * CNRS (UMR 5800), the University of Bordeaux, 8 | * and the Bordeaux INP 9 | * 10 | * Author: 11 | * Lionel Clément 12 | * LaBRI - Université Bordeaux 13 | * 351, cours de la Libération 14 | * 33405 Talence Cedex - France 15 | * lionel.clement@u-bordeaux.fr 16 | * 17 | * This file is part of ELVEX. 18 | * 19 | ************************************************** */ 20 | 21 | // 22 | // Morphological transformation for English 23 | // 24 | 25 | #include 26 | #define YY_NO_INPUT 27 | 28 | %} 29 | 30 | %option noyywrap 31 | 32 | %s NEXT BEGINLINE 33 | 34 | space [ ] 35 | weakPonct [,;:()'-] 36 | strongPonct [.!?/] 37 | mesure mm|cm|m|dm|km|m2|m3|A|[oO]hm|V|VA|gr|[kK]g 38 | 39 | %% 40 | 41 | { 42 | [ \t] ; 43 | [[:lower:]] { 44 | char cpy = *yytext; 45 | unput(toupper(cpy)); 46 | BEGIN(BEGINLINE); 47 | } 48 | . {yyless(0); BEGIN(BEGINLINE);} 49 | } 50 | 51 | . {yyless(0); unput(' '); BEGIN(NEXT);} 52 | 53 | { 54 | {space}+/[,?!.;:-] {} 55 | {space}[dD]o{space}+not { std::cout << yytext[0] << yytext[1] << "on't" ; } 56 | {space}[dD]oes{space}+not { std::cout << yytext[0] << yytext[1] << "oesn't" ; } 57 | {space}[dD]id{space}+not { std::cout << yytext[0] << yytext[1] << "idn't" ; } 58 | {space}[iI]s{space}+not { std::cout << yytext[0] << yytext[1] << "sn't" ; } 59 | {space}[wW]as{space}+not { std::cout << yytext[0] << yytext[1] << "asn't" ; } 60 | {space}[wW]ere{space}+not { std::cout << yytext[0] << yytext[1] << "eren't" ; } 61 | {space}[aA]re{space}+not { std::cout << yytext[0] << yytext[1] << "ren't" ; } 62 | {space}[hH]ave{space}+not { std::cout << yytext[0] << yytext[1] << "aven't" ; } 63 | {space}[hH]as{space}+not { std::cout << yytext[0] << yytext[1] << "asn't" ; } 64 | {space}[hH]ad{space}+not { std::cout << yytext[0] << yytext[1] << "adn't" ; } 65 | {space}[wW]ill{space}+not { std::cout << yytext[0] << yytext[1] << "on't" ; } 66 | \n {ECHO; BEGIN(INITIAL);} 67 | } 68 | 69 | %% 70 | 71 | int main(){ 72 | yylex(); 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /src/statements.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_STATEMENTS_H 21 | #define ELVEX_STATEMENTS_H 22 | 23 | #include 24 | #include 25 | #include "facade.hpp" 26 | #include "serializable.hpp" 27 | #include "shared_ptr.hpp" 28 | #include "parser.hpp" 29 | #include "generator.hpp" 30 | 31 | class Statements : public Facade, 32 | //public Serializable, 33 | public std::enable_shared_from_this 34 | { 35 | 36 | public: 37 | typedef std::list list_statement; 38 | 39 | private: 40 | statementPtr guard; 41 | list_statement statements; 42 | 43 | Statements(const statementPtr &); 44 | 45 | //void makeSerialString(void); 46 | 47 | public: 48 | ~Statements(); 49 | 50 | static statementsPtr create(const statementPtr & = statementPtr()); 51 | 52 | size_t size(void); 53 | 54 | list_statement::const_iterator begin(void); 55 | 56 | list_statement::const_iterator end(void); 57 | 58 | list_statement::const_iterator cbegin(void) const; 59 | 60 | list_statement::const_iterator cend(void) const; 61 | 62 | void addStatement(const statementPtr &); 63 | 64 | void renameVariables(uint32_t code); 65 | 66 | bool findVariable(uint32_t code); 67 | 68 | void print(std::ostream &outStream, uint8_t tabulationLenght, uint8_t tabulation, uint32_t color, uint32_t bgcolor, bool ln, std::string leftSep, std::string rightSep, std::string sep) const; 69 | 70 | statementsPtr clone(const std::bitset &savedFlags); 71 | 72 | void toggleEnable(class Item *item, class Generator *synthesizer, bool &effect, bool on); 73 | 74 | void apply(class Item *item, Parser &parser, Generator *synthesizer, bool &effect, bool verbose); 75 | 76 | }; 77 | 78 | #endif // ELVEX_STATEMENTS_H 79 | -------------------------------------------------------------------------------- /src/compacted-lexicon-buffer.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include "compacted-lexicon-buffer.hpp" 21 | 22 | /* ************************************************** 23 | * 24 | ************************************************** */ 25 | CompactedLexiconBuffer::CompactedLexiconBuffer(uint32_t next, uint32_t offset) { 26 | this->next = next; 27 | this->offset = offset; 28 | } 29 | 30 | /* ************************************************** 31 | * 32 | ************************************************** */ 33 | CompactedLexiconBuffer::CompactedLexiconBuffer() { 34 | this->next = (uint32_t) (~0UL); 35 | this->offset = (uint32_t) (~0UL); 36 | } 37 | 38 | /* ************************************************** 39 | * 40 | ************************************************** */ 41 | uint32_t CompactedLexiconBuffer::getOffset() const { 42 | return offset; 43 | } 44 | 45 | /* ************************************************** 46 | * 47 | ************************************************** */ 48 | uint32_t CompactedLexiconBuffer::getNext() const { 49 | return next; 50 | } 51 | 52 | /* ************************************************** 53 | * 54 | ************************************************** */ 55 | bool CompactedLexiconBuffer::isNext() const { 56 | return next != (uint32_t) (~0UL); 57 | } 58 | 59 | /* ************************************************** 60 | * 61 | ************************************************** */ 62 | bool CompactedLexiconBuffer::isOffset() const { 63 | return offset != (uint32_t) (~0UL); 64 | } 65 | 66 | /* ************************************************** 67 | * 68 | ************************************************** */ 69 | void CompactedLexiconBuffer::print(std::ostream &out) const { 70 | out << (long int) next << ' ' << (long int) offset << std::endl; 71 | } 72 | 73 | -------------------------------------------------------------------------------- /src/node.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_NODE_H 21 | #define ELVEX_NODE_H 22 | 23 | #include 24 | #include 25 | 26 | #ifdef OUTPUT_XML 27 | #include 28 | #endif 29 | 30 | #include "facade.hpp" 31 | #include "shared_ptr.hpp" 32 | 33 | class Node : 34 | public Facade, 35 | public std::enable_shared_from_this { 36 | 37 | public: 38 | typedef std::vector vectorForests; 39 | 40 | private: 41 | vectorForests forests; 42 | std::forward_list output; 43 | bool withSpaces; 44 | bool bidirectional; 45 | bool permutable; 46 | 47 | public: 48 | Node(bool withSpaces, bool bidirectional, bool permutable); 49 | 50 | ~Node(void); 51 | 52 | static nodePtr create(bool withSpaces, bool bidirectional, bool permutable); 53 | 54 | bool empty() const; 55 | 56 | vectorForests::iterator begin(); 57 | 58 | vectorForests::iterator end(); 59 | 60 | vectorForests::const_iterator cbegin() const; 61 | 62 | vectorForests::const_iterator cend() const; 63 | 64 | size_t size() const; 65 | 66 | forestPtr at(size_t); 67 | 68 | void push_back(const forestPtr&); 69 | 70 | const std::forward_list::const_iterator output_cbegin(void) const; 71 | 72 | const std::forward_list::const_iterator output_cend(void) const; 73 | 74 | bool getWithSpace() const; 75 | 76 | #ifdef OUTPUT_XML 77 | void toXML(xmlNodePtr, xmlNodePtr) const; 78 | #endif 79 | 80 | void generateLR(std::string ¤tCombination, vectorForests::const_iterator forestIt); 81 | void generateRL(std::string currentCombination, vectorForests::const_iterator forestIt); 82 | void generatePermutations(vectorForests& forests, int start, int end); 83 | void generate(bool randomResult, bool singleResult); 84 | 85 | }; 86 | 87 | #endif // ELVEX_NODE_H 88 | 89 | -------------------------------------------------------------------------------- /src/forestmap.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include 21 | 22 | #include "forestmap.hpp" 23 | #include "messages.hpp" 24 | #include "forestidentifier.hpp" 25 | #include "forest.hpp" 26 | #include "vartable.hpp" 27 | 28 | /* ************************************************** 29 | * 30 | ************************************************** */ 31 | ForestMap::ForestMap() 32 | { 33 | NEW; 34 | } 35 | 36 | /* ************************************************** 37 | * 38 | ************************************************** */ 39 | ForestMap::~ForestMap() 40 | { 41 | DELETE; 42 | for (auto &i : data) 43 | { 44 | forestPtr tmp = i.second; 45 | if (tmp) 46 | tmp.reset(); 47 | } 48 | } 49 | 50 | /* ************************************************** 51 | * 52 | ************************************************** */ 53 | ForestMap::map::const_iterator ForestMap::find(class ForestIdentifier *forestIdentifier) const 54 | { 55 | return data.find(forestIdentifier); 56 | } 57 | 58 | /* ************************************************** 59 | * 60 | ************************************************** */ 61 | ForestMap::map::const_iterator ForestMap::cbegin() const 62 | { 63 | return data.cbegin(); 64 | } 65 | 66 | /* ************************************************** 67 | * 68 | ************************************************** */ 69 | ForestMap::map::const_iterator ForestMap::cend() const 70 | { 71 | return data.cend(); 72 | } 73 | 74 | /* ************************************************** 75 | * 76 | ************************************************** */ 77 | void ForestMap::clear() 78 | { 79 | return data.clear(); 80 | } 81 | 82 | /* ************************************************** 83 | * 84 | ************************************************** */ 85 | bool ForestMap::insert(class ForestIdentifier *key, forestPtr value) 86 | { 87 | return data.insert(std::make_pair(key, value)).second; 88 | } 89 | -------------------------------------------------------------------------------- /src/messages.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_MESSAGES_H 21 | #define ELVEX_MESSAGES_H 22 | 23 | #include 24 | #include "fatal_exception.hpp" 25 | 26 | #ifdef TRACE_MALLOC 27 | 28 | #define NEW \ 29 | { \ 30 | std::cerr << "$$$ New " << __FILE__ << std::endl; \ 31 | } 32 | 33 | #define DELETE \ 34 | { \ 35 | std::cerr << "$$$ Delete " << __FILE__ << std::endl; \ 36 | } 37 | #else 38 | 39 | #define NEW \ 40 | { \ 41 | } 42 | #define DELETE \ 43 | { \ 44 | } 45 | 46 | #endif 47 | 48 | #define CERR_LINE \ 49 | { \ 50 | std::cerr << __FILE__ << "(" << std::dec << __LINE__ << ")" \ 51 | << "
" << std::endl; \ 52 | } 53 | 54 | #define COUT_LINE \ 55 | { \ 56 | std::cout << "
" << __FILE__ << "(" << std::dec << __LINE__ << ")" \ 57 | << "
" << std::endl; \ 58 | std::flush(std::cout); \ 59 | } 60 | 61 | #define FATAL_ERROR_UNEXPECTED \ 62 | { \ 63 | CERR_LINE; \ 64 | throw fatal_exception("*** unexpected"); \ 65 | } 66 | 67 | #define WARNING(msg) \ 68 | { \ 69 | std::cerr << "*** warning: " << msg << std::endl; \ 70 | } 71 | 72 | #endif // ELVEX_MESSAGES_H 73 | -------------------------------------------------------------------------------- /test/test-BigLexicon.test: -------------------------------------------------------------------------------- 1 | FORM_5_21 ... [attrMorpho:_5,attrPattern:_5,attrInteger:148,attrString:"148"] 2 | FORM_5_8 ... [attrMorpho:_5,attrPattern:_5,attrInteger:135,attrString:"135"] 3 | FORM_5_12 ... [attrMorpho:_5,attrPattern:_5,attrInteger:139,attrString:"139"] 4 | FORM_5_23 ... [attrMorpho:_5,attrPattern:_5,attrInteger:150,attrString:"150"] 5 | FORM_5_18 ... [attrMorpho:_5,attrPattern:_5,attrInteger:145,attrString:"145"] 6 | FORM_5_29 ... [attrMorpho:_5,attrPattern:_5,attrInteger:156,attrString:"156"] 7 | FORM_5_6 ... [attrMorpho:_5,attrPattern:_5,attrInteger:133,attrString:"133"] 8 | FORM_5_30 ... [attrMorpho:_5,attrPattern:_5,attrInteger:157,attrString:"157"] 9 | FORM_5_15 ... [attrMorpho:_5,attrPattern:_5,attrInteger:142,attrString:"142"] 10 | FORM_5_31 ... [attrMorpho:_5,attrPattern:_5,attrInteger:158,attrString:"158"] 11 | FORM_5_2 ... [attrMorpho:_5,attrPattern:_5,attrInteger:129,attrString:"129"] 12 | FORM_5_20 ... [attrMorpho:_5,attrPattern:_5,attrInteger:147,attrString:"147"] 13 | FORM_5_27 ... [attrMorpho:_5,attrPattern:_5,attrInteger:154,attrString:"154"] 14 | FORM_5_11 ... [attrMorpho:_5,attrPattern:_5,attrInteger:138,attrString:"138"] 15 | FORM_5_14 ... [attrMorpho:_5,attrPattern:_5,attrInteger:141,attrString:"141"] 16 | FORM_5_28 ... [attrMorpho:_5,attrPattern:_5,attrInteger:155,attrString:"155"] 17 | FORM_5_17 ... [attrMorpho:_5,attrPattern:_5,attrInteger:144,attrString:"144"] 18 | FORM_5_16 ... [attrMorpho:_5,attrPattern:_5,attrInteger:143,attrString:"143"] 19 | FORM_5_22 ... [attrMorpho:_5,attrPattern:_5,attrInteger:149,attrString:"149"] 20 | FORM_5_10 ... [attrMorpho:_5,attrPattern:_5,attrInteger:137,attrString:"137"] 21 | FORM_5_1 ... [attrMorpho:_5,attrPattern:_5,attrInteger:128,attrString:"128"] 22 | FORM_5_7 ... [attrMorpho:_5,attrPattern:_5,attrInteger:134,attrString:"134"] 23 | FORM_5_25 ... [attrMorpho:_5,attrPattern:_5,attrInteger:152,attrString:"152"] 24 | FORM_5_13 ... [attrMorpho:_5,attrPattern:_5,attrInteger:140,attrString:"140"] 25 | FORM_5_26 ... [attrMorpho:_5,attrPattern:_5,attrInteger:153,attrString:"153"] 26 | FORM_5_3 ... [attrMorpho:_5,attrPattern:_5,attrInteger:130,attrString:"130"] 27 | FORM_5_32 ... [attrMorpho:_5,attrPattern:_5,attrInteger:159,attrString:"159"] 28 | FORM_5_9 ... [attrMorpho:_5,attrPattern:_5,attrInteger:136,attrString:"136"] 29 | FORM_5_5 ... [attrMorpho:_5,attrPattern:_5,attrInteger:132,attrString:"132"] 30 | FORM_5_24 ... [attrMorpho:_5,attrPattern:_5,attrInteger:151,attrString:"151"] 31 | FORM_5_4 ... [attrMorpho:_5,attrPattern:_5,attrInteger:131,attrString:"131"] 32 | FORM_5_19 ... [attrMorpho:_5,attrPattern:_5,attrInteger:146,attrString:"146"] 33 | -------------------------------------------------------------------------------- /src/forestidentifier.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include "forestidentifier.hpp" 21 | #include "messages.hpp" 22 | #include "vartable.hpp" 23 | 24 | /* ************************************************************ 25 | * * 26 | ************************************************************ */ 27 | ForestIdentifier::ForestIdentifier(uint32_t code, uint32_t from, uint32_t to) 28 | { 29 | NEW; 30 | this->code = code; 31 | this->from = from; 32 | this->to = to; 33 | //this->featuresSerialString = featuresSerialString; 34 | } 35 | 36 | /* ************************************************** 37 | * 38 | ************************************************** */ 39 | ForestIdentifier::~ForestIdentifier() 40 | { 41 | DELETE; 42 | } 43 | 44 | /* ************************************************************ 45 | * * 46 | ************************************************************ */ 47 | class ForestIdentifier * 48 | ForestIdentifier::create(uint32_t code, 49 | uint32_t from, 50 | uint32_t to) 51 | { 52 | return new ForestIdentifier(code, from, to); 53 | } 54 | 55 | /* ************************************************** 56 | * 57 | ************************************************** */ 58 | void ForestIdentifier::makeSerialString() 59 | { 60 | std::ostringstream stream; 61 | stream << '#' << std::hex << code << '#' << from << '#' << to; 62 | stream.flush(); 63 | serialString = stream.str(); 64 | } 65 | 66 | /* ************************************************** 67 | * 68 | ************************************************** */ 69 | size_t ForestIdentifier::Hash::operator()(ForestIdentifier *forestIdentifier) const 70 | { 71 | return forestIdentifier->hash(); 72 | } 73 | 74 | /* ************************************************** 75 | * 76 | ************************************************** */ 77 | bool ForestIdentifier::KeyEqual::operator()(ForestIdentifier *forestIdentifier1, ForestIdentifier *forestIdentifier2) const 78 | { 79 | return forestIdentifier1->peekSerialString() == forestIdentifier2->peekSerialString(); 80 | } 81 | -------------------------------------------------------------------------------- /src/memoization-map.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifdef TRACE_MEMOIZATION 21 | #include 22 | #endif 23 | #include 24 | #include "memoization-map.hpp" 25 | #include "features.hpp" 26 | #include "forestidentifier.hpp" 27 | 28 | /* ************************************************************ 29 | * 30 | ************************************************************ */ 31 | MemoizationMap::map::const_iterator MemoizationMap::find(std::string const &key) const 32 | { 33 | auto memItem = memoizationMap.find(key); 34 | #ifdef TRACE_MEMOIZATION 35 | if (memItem != memoizationMap.end()) 36 | { 37 | std::cout << "

####################### RECORDED SHIFT FOUND #######################

" << std::endl; 38 | std::cout << "
"; 39 | std::cout << std::endl; 40 | } 41 | #endif 42 | return memItem; 43 | } 44 | 45 | /* ************************************************************ 46 | * 47 | ************************************************************ */ 48 | MemoizationMap::map::const_iterator MemoizationMap::cend() const 49 | { 50 | return memoizationMap.cend(); 51 | } 52 | 53 | /* ************************************************************ 54 | * 55 | ************************************************************ */ 56 | void MemoizationMap::insert(std::string const &key, featuresPtr features, class ForestIdentifier *forestIdentifier) 57 | { 58 | #ifdef TRACE_MEMOIZATION 59 | std::cout << "

####################### RECORD SHIFT #######################

" << std::endl; 60 | std::cout << "
"; 61 | std::cout << std::endl; 62 | #endif 63 | class MemoizationValue *value = MemoizationValue::create(std::move(features), std::move(forestIdentifier)); 64 | auto memItem = memoizationMap.find(key); 65 | if (memItem != memoizationMap.end()) 66 | { 67 | memItem->second.push_back(value); 68 | } 69 | else 70 | { 71 | std::vector values; 72 | values.push_back(value); 73 | memoizationMap[key] = values; 74 | } 75 | } 76 | 77 | /* ************************************************************ 78 | * 79 | ************************************************************ */ 80 | void MemoizationMap::clear() 81 | { 82 | memoizationMap.clear(); 83 | } 84 | -------------------------------------------------------------------------------- /src/compacted-lexicon.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef COMPACTEDLEXICON_H 21 | #define COMPACTEDLEXICON_H 22 | 23 | #define SEP_PREF "" 24 | #define SEP_UW "UNKNOWN" 25 | #define SEP_SUFF "\n" 26 | #define SEP_OR "|" 27 | 28 | #include 29 | #include 30 | #include "compacted-lexicon-tree.hpp" 31 | #include "lexicon.hpp" 32 | 33 | extern bool isLexString; 34 | extern char *lexString; 35 | extern char *currentLexString; 36 | 37 | extern class Entry *localEntry; 38 | 39 | class CompactedLexicon 40 | { 41 | 42 | private: 43 | std::string directoryName; 44 | std::string fileName; 45 | FILE *fsaFile; 46 | std::string fsaFileName; 47 | FILE *dataFile; 48 | std::string dataFileName; 49 | std::istream *inputStream = &std::cin; 50 | CompactedLexiconTree *compactedLexicon; 51 | 52 | public: 53 | char *buffer; 54 | struct CompactedLexiconFsa *fsa; 55 | struct CompactedLexiconBuffer *info; 56 | uint32_t init; 57 | class CompactedLexiconTree *lexiconInit; 58 | 59 | public: 60 | CompactedLexicon(std::string &directoryName, std::string &fileName); 61 | 62 | void printResults(std::ostream &, uint32_t index, bool sep) const; 63 | 64 | uint32_t search(uint32_t index, const std::string &) const; 65 | 66 | void saveFsa(bool verbose); 67 | 68 | void loadFsa(bool verbose); 69 | 70 | void openFiles(const std::string &mode); 71 | 72 | void closeFiles(); 73 | 74 | static std::string unif(const std::string &fs1, const std::string &fs2, bool verbose); 75 | 76 | void addToData(const std::string &entry, const std::string &form, const std::string &features); 77 | 78 | void addPattern(Lexicon &pattern, Lexicon &morpho, const std::string &input, const std::string &fs, const std::string &lemma, 79 | const std::string &pos, bool verbose); 80 | 81 | void addForms(const std::string &input, std::string inputSearch, const std::string &features, Lexicon &morpho, bool verbose); 82 | 83 | void buildEntries(class Lexicon &pattern, class Lexicon &morpho, bool verbose); 84 | 85 | void loadData(bool verbose); 86 | 87 | void consult(); 88 | 89 | void print(std::ostream &); 90 | 91 | private: 92 | void print(unsigned int, const std::string &, std::ostream &); 93 | }; 94 | 95 | #endif // COMPACTEDLEXICON_H 96 | -------------------------------------------------------------------------------- /src/facade.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include "facade.hpp" 21 | #include "messages.hpp" 22 | 23 | /* ************************************************** 24 | * 25 | ************************************************** */ 26 | Facade::Facade(std::size_t id, const std::bitset &args) 27 | { 28 | NEW; 29 | uniqId = UniqId(id); 30 | flags = Flags(args); 31 | } 32 | 33 | /* ************************************************** 34 | * 35 | ************************************************** */ 36 | Facade::~Facade() 37 | { 38 | DELETE; 39 | } 40 | 41 | /* ************************************************** 42 | * 43 | ************************************************** */ 44 | std::bitset &Facade::getFlags() 45 | { 46 | return flags.getFlags(); 47 | } 48 | 49 | /* ************************************************** 50 | * 51 | ************************************************** */ 52 | bool Facade::isSetFlags(const std::bitset &cmp) const 53 | { 54 | return flags.isSet(cmp); 55 | } 56 | 57 | /* ************************************************** 58 | * 59 | ************************************************** */ 60 | bool Facade::isUnsetFlags(const std::bitset &cmp) const 61 | { 62 | return flags.isUnset(cmp); 63 | } 64 | 65 | /* ************************************************** 66 | * 67 | ************************************************** */ 68 | void Facade::addFlags(const std::bitset &f) 69 | { 70 | flags.add(f); 71 | } 72 | 73 | /* ************************************************** 74 | * 75 | ************************************************** */ 76 | void Facade::subFlags(const std::bitset &f) 77 | { 78 | flags.sub(f); 79 | } 80 | 81 | /* ************************************************** 82 | * 83 | ************************************************** */ 84 | void Facade::printFlags(std::ostream &out) const 85 | { 86 | flags.print(out); 87 | } 88 | 89 | /* ************************************************** 90 | * 91 | ************************************************** */ 92 | std::uint32_t Facade::getId(void) const 93 | { 94 | return uniqId.getId(); 95 | } 96 | 97 | /* ************************************************** 98 | * 99 | ************************************************** */ 100 | std::string Facade::getIdStr(void) const 101 | { 102 | return uniqId.getIdStr(); 103 | } 104 | -------------------------------------------------------------------------------- /src/vartable.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_VARTABLE_H 21 | #define ELVEX_VARTABLE_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "bitset.hpp" 28 | #include "shared_ptr.hpp" 29 | 30 | class Vartable 31 | { 32 | 33 | public: 34 | static uint32_t IS_A_FORM; 35 | static uint32_t DOES_NOT_CONTAIN_A_HEAD; 36 | 37 | 38 | // symbol => bitset 39 | // i.e. subject => 36 (MAXBITS values) 40 | typedef std::unordered_map string_to_bitset; 41 | typedef string_to_bitset::iterator string_to_bitset_iterator; 42 | typedef string_to_bitset::const_iterator string_to_bitset_const_iterator; 43 | 44 | // int => variable 45 | typedef std::unordered_map uint32_t_to_string; 46 | typedef uint32_t_to_string::iterator uint32_t_to_string_iterator; 47 | typedef uint32_t_to_string::const_iterator uint32_t_to_string_const_iterator; 48 | 49 | // string => int 50 | // i.e. "TO_SAY" => 89 (MAX_UINT values) 51 | typedef std::unordered_map string_to_uint32_t; 52 | typedef string_to_uint32_t::iterator string_to_uint32_t_iterator; 53 | typedef string_to_uint32_t::const_iterator string_to_uint32_t_const_iterator; 54 | 55 | private: 56 | static std::bitset variableMapIndex; 57 | static uint32_t codeMapIndex; 58 | static string_to_bitset nameToBitsetMap; 59 | static uint32_t_to_string codeToNameMap; 60 | static string_to_uint32_t nameToCodeMap; 61 | static uint32_t_to_string bitToNameMap; 62 | 63 | public: 64 | Vartable(); 65 | 66 | static bitsetPtr createSymbol(const std::string &); // variable -> bitset 67 | 68 | static bitsetPtr createSymbol(const std::string &name, uint32_t code); 69 | 70 | static uint32_t nameToCode(const std::string &); // identifier -> code 71 | 72 | static uint32_t nameToCode(const std::string &, uint32_t code); // identifier -> code 73 | 74 | static std::string &codeToName(uint32_t); // code -> identifier 75 | 76 | static std::string &bitToName(uint32_t); // bit weight -> identifier 77 | 78 | static void insertCodeMap(const uint32_t, const std::string &); 79 | 80 | static uint32_t_to_string_iterator bitMapFind(uint32_t); 81 | 82 | static uint32_t_to_string_const_iterator bitMapcEnd(void); 83 | 84 | static void renameVariables(std::string &data, uint32_t code); 85 | 86 | }; 87 | 88 | #endif // ELVEX_VARTABLE_H 89 | -------------------------------------------------------------------------------- /doc/doc-en.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\hyper@newdestlabel[2]{} 3 | \providecommand\babel@aux[2]{} 4 | \@nameuse{bbl@beforestart} 5 | \catcode `:\active 6 | \catcode `;\active 7 | \catcode `!\active 8 | \catcode `?\active 9 | \providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} 10 | \HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined 11 | \global\let\oldcontentsline\contentsline 12 | \gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} 13 | \global\let\oldnewlabel\newlabel 14 | \gdef\newlabel#1#2{\newlabelxx{#1}#2} 15 | \gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} 16 | \AtEndDocument{\ifx\hyper@anchor\@undefined 17 | \let\contentsline\oldcontentsline 18 | \let\newlabel\oldnewlabel 19 | \fi} 20 | \fi} 21 | \global\let\hyper@last\relax 22 | \gdef\HyperFirstAtBeginDocument#1{#1} 23 | \providecommand\HyField@AuxAddToFields[1]{} 24 | \providecommand\HyField@AuxAddToCoFields[2]{} 25 | \babel@aux{french}{} 26 | \@writefile{toc}{\contentsline {section}{\numberline {1}Grammar by sample}{1}{section.1}\protected@file@percent } 27 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.1}Syntagmatic description (\textit {Context-Free Grammar rules})}{2}{subsection.1.1}\protected@file@percent } 28 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.2}Operational semantics}{2}{subsection.1.2}\protected@file@percent } 29 | \@writefile{toc}{\contentsline {section}{\numberline {2}Elvex notations}{6}{section.2}\protected@file@percent } 30 | \@writefile{toc}{\contentsline {subsection}{\numberline {2.1}Operational Semantics}{6}{subsection.2.1}\protected@file@percent } 31 | \@writefile{toc}{\contentsline {paragraph}{Notations}{6}{section*.5}\protected@file@percent } 32 | \newlabel{0-a}{{2a}{12}{Variable evaluation}{Item.5}{}} 33 | \newlabel{0-a}{{2b}{12}{Variable evaluation}{Item.6}{}} 34 | \newlabel{0-a}{{2c}{12}{Variable evaluation}{Item.7}{}} 35 | \newlabel{0-a}{{2d}{12}{Variable evaluation}{Item.8}{}} 36 | \@writefile{toc}{\contentsline {subsection}{\numberline {2.2}Lexicon}{12}{subsection.2.2}\protected@file@percent } 37 | \@writefile{toc}{\contentsline {subsection}{\numberline {2.3}Input}{15}{subsection.2.3}\protected@file@percent } 38 | \@writefile{toc}{\contentsline {section}{\numberline {3}Design pattern (to be completed)}{17}{section.3}\protected@file@percent } 39 | \@writefile{toc}{\contentsline {section}{\numberline {4}The \texttt {elvex} command}{21}{section.4}\protected@file@percent } 40 | \@writefile{toc}{\contentsline {subsubsection}{\numberline {4.0.1}try \texttt {Elvex}}{21}{subsubsection.4.0.1}\protected@file@percent } 41 | \@writefile{toc}{\contentsline {subsection}{\numberline {4.1}\texttt {Elvex} command}{21}{subsection.4.1}\protected@file@percent } 42 | \@writefile{toc}{\contentsline {subsection}{\numberline {4.2}Grammar debugging}{23}{subsection.4.2}\protected@file@percent } 43 | \@writefile{toc}{\contentsline {subsection}{\numberline {4.3}\texttt {elvexbuildlexicon} for managing big lexicons}{23}{subsection.4.3}\protected@file@percent } 44 | \@writefile{toc}{\contentsline {paragraph}{}{24}{section*.13}\protected@file@percent } 45 | \gdef \@abspage@last{24} 46 | -------------------------------------------------------------------------------- /test/test-En.stdin: -------------------------------------------------------------------------------- 1 | Axiom [HEAD:succ, i: [HEAD:PRIVILEGE, i:[HEAD:STUDENT, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:ELVEX, ID:2]]], ii: [HEAD:EUPHORIC, i:[HEAD:pro, @_3, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:pro, @s, @nohum, ID:2]]], vtense:future] 2 | Axiom [HEAD:succ, i: [HEAD:PRIVILEGE, i:[HEAD:STUDENT, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:ELVEX, ID:2]]], ii: [HEAD:EUPHORIC, i:[HEAD:pro, @_3, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:pro, @s, @nohum, ID:2]]], vtense:future_continuous] 3 | Axiom [HEAD:succ, i: [HEAD:PRIVILEGE, i:[HEAD:STUDENT, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:ELVEX, ID:2]]], ii: [HEAD:EUPHORIC, i:[HEAD:pro, @_3, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:pro, @s, @nohum, ID:2]]], vtense:future_perfect] 4 | Axiom [HEAD:succ, i: [HEAD:PRIVILEGE, i:[HEAD:STUDENT, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:ELVEX, ID:2]]], ii: [HEAD:EUPHORIC, i:[HEAD:pro, @_3, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:pro, @s, @nohum, ID:2]]], vtense:future_perfect_continuous] 5 | Axiom [HEAD:succ, i: [HEAD:PRIVILEGE, i:[HEAD:STUDENT, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:ELVEX, ID:2]]], ii: [HEAD:EUPHORIC, i:[HEAD:pro, @_3, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:pro, @s, @nohum, ID:2]]], vtense:past_continous] 6 | Axiom [HEAD:succ, i: [HEAD:PRIVILEGE, i:[HEAD:STUDENT, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:ELVEX, ID:2]]], ii: [HEAD:EUPHORIC, i:[HEAD:pro, @_3, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:pro, @s, @nohum, ID:2]]], vtense:past_perfect] 7 | Axiom [HEAD:succ, i: [HEAD:PRIVILEGE, i:[HEAD:STUDENT, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:ELVEX, ID:2]]], ii: [HEAD:EUPHORIC, i:[HEAD:pro, @_3, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:pro, @s, @nohum, ID:2]]], vtense:past_perfect_continuous] 8 | Axiom [HEAD:succ, i: [HEAD:PRIVILEGE, i:[HEAD:STUDENT, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:ELVEX, ID:2]]], ii: [HEAD:EUPHORIC, i:[HEAD:pro, @_3, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:pro, @s, @nohum, ID:2]]], vtense:present] 9 | Axiom [HEAD:succ, i: [HEAD:PRIVILEGE, i:[HEAD:STUDENT, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:ELVEX, ID:2]]], ii: [HEAD:EUPHORIC, i:[HEAD:pro, @_3, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:pro, @s, @nohum, ID:2]]], vtense:present_continuous] 10 | Axiom [HEAD:succ, i: [HEAD:PRIVILEGE, i:[HEAD:STUDENT, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:ELVEX, ID:2]]], ii: [HEAD:EUPHORIC, i:[HEAD:pro, @_3, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:pro, @s, @nohum, ID:2]]], vtense:present_perfect] 11 | Axiom [HEAD:succ, i: [HEAD:PRIVILEGE, i:[HEAD:STUDENT, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:ELVEX, ID:2]]], ii: [HEAD:EUPHORIC, i:[HEAD:pro, @_3, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:pro, @s, @nohum, ID:2]]], vtense:present_perfect_continuous] 12 | Axiom [HEAD:succ, i: [HEAD:PRIVILEGE, i:[HEAD:STUDENT, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:ELVEX, ID:2]]], ii: [HEAD:EUPHORIC, i:[HEAD:pro, @_3, @m, @s, ID:1], ii:[HEAD:TO_USE, i:[ID:1], ii:[HEAD:pro, @s, @nohum, ID:2]]], vtense:preterite] 13 | -------------------------------------------------------------------------------- /src/feature.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_FEATURE_H 21 | #define ELVEX_FEATURE_H 22 | 23 | #include "facade.hpp" 24 | #include "shared_ptr.hpp" 25 | #include "serializable.hpp" 26 | #include "variableflag.hpp" 27 | 28 | #ifdef OUTPUT_XML 29 | #include 30 | #endif 31 | 32 | class Feature : public Facade, 33 | public Serializable, 34 | public std::enable_shared_from_this 35 | { 36 | 37 | public: 38 | enum Type 39 | { 40 | _HEAD_ = 0, 41 | _LEMMA_, 42 | _CONSTANT_, 43 | _FORM_, 44 | _VARIABLE_, 45 | }; 46 | 47 | static const Type first_type = _HEAD_; 48 | static const Type last_type = _VARIABLE_; 49 | 50 | private: 51 | enum Type type; 52 | 53 | bitsetPtr attribute; 54 | 55 | uint32_t code; 56 | 57 | valuePtr value; 58 | 59 | void makeSerialString(void); 60 | 61 | VariableFlag variableFlag; 62 | 63 | public: 64 | Feature(Type, bitsetPtr, valuePtr); 65 | 66 | Feature(Type, uint32_t, valuePtr); 67 | 68 | ~Feature(); 69 | 70 | static featurePtr createConstant(bitsetPtr attribute = bitsetPtr(), valuePtr value = valuePtr()); 71 | 72 | static featurePtr createHead(valuePtr value); 73 | 74 | static featurePtr createForm(valuePtr value); 75 | 76 | static featurePtr createLemma(valuePtr value); 77 | 78 | static featurePtr createVariable(uint32_t code, valuePtr value = valuePtr()); 79 | 80 | bitsetPtr getAttribute(void) const; 81 | 82 | uint32_t getCode(void) const; 83 | 84 | void setAttribute(const bitsetPtr); 85 | 86 | valuePtr getValue(void) const; 87 | 88 | void setValue(const valuePtr); 89 | 90 | enum Type getType(void) const; 91 | 92 | void setType(const enum Type); 93 | 94 | bool isForm() const; 95 | 96 | bool isHead() const; 97 | 98 | bool isLemma() const; 99 | 100 | bool isConstant() const; 101 | 102 | bool isVariable() const; 103 | 104 | std::string attributeToString(void) const; 105 | 106 | featurePtr clone(void) const; 107 | 108 | void print(std::ostream &) const; 109 | 110 | void flatPrint(std::ostream &) const; 111 | 112 | #ifdef OUTPUT_XML 113 | void toXML(xmlNodePtr nodeRoot); 114 | #endif 115 | 116 | bool renameVariables(uint32_t); 117 | 118 | void enable(const statementPtr &, class Item *, class Generator *synthesizer, bool &, bool); 119 | 120 | bool findVariable(uint32_t key) const; 121 | 122 | bool containsVariable(void); 123 | 124 | }; 125 | 126 | #endif // ELVEX_FEATURE_H 127 | -------------------------------------------------------------------------------- /src/lexicon.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include "lexicon.hpp" 21 | #include 22 | #include 23 | #include "messages.hpp" 24 | 25 | std::vector Lexicon::emptyList = std::vector(); 26 | 27 | /* ************************************************** 28 | * 29 | ************************************************** */ 30 | Lexicon::Lexicon(std::string name) 31 | { 32 | NEW; 33 | this->name = name; 34 | } 35 | 36 | /* ************************************************** 37 | * 38 | ************************************************** */ 39 | Lexicon::unordered_map::const_iterator Lexicon::cbegin(void) 40 | { 41 | return the_map.cbegin(); 42 | } 43 | 44 | /* ************************************************** 45 | * 46 | ************************************************** */ 47 | Lexicon::unordered_map::const_iterator Lexicon::cend(void) 48 | { 49 | return the_map.cend(); 50 | } 51 | 52 | /* ************************************************** 53 | * 54 | ************************************************** */ 55 | std::size_t Lexicon::size(void) 56 | { 57 | return the_map.size(); 58 | } 59 | 60 | /* ************************************************** 61 | * 62 | ************************************************** */ 63 | void Lexicon::add(std::string key, std::string value) 64 | { 65 | //CERR_LINE; 66 | //std::cerr << "Lexicon::add [key:\"" << key << "\", value:\"" << value << "\"]" << std::endl; 67 | unordered_map::iterator it = the_map.find(key); 68 | if (it != the_map.end()) 69 | (*it).second.push_back(value); 70 | else 71 | { 72 | std::vector list = std::vector(); 73 | list.push_back(value); 74 | the_map[key] = list; 75 | } 76 | } 77 | 78 | /* ************************************************** 79 | * 80 | ************************************************** */ 81 | std::vector Lexicon::find(std::string key) 82 | { 83 | unordered_map::const_iterator it = the_map.find(key); 84 | if (it != the_map.end()) 85 | { 86 | return (*it).second; 87 | } 88 | else 89 | { 90 | return emptyList; 91 | } 92 | } 93 | 94 | /* ************************************************** 95 | * 96 | ************************************************** */ 97 | std::size_t Lexicon::count(std::string key) 98 | { 99 | return the_map.count(key); 100 | } 101 | 102 | /* ************************************************** 103 | * 104 | ************************************************** */ 105 | std::string &Lexicon::toString(void) const 106 | { 107 | static std::string result; 108 | std::ostringstream oss; 109 | oss << the_map.size(); 110 | result = oss.str(); 111 | return result; 112 | } 113 | -------------------------------------------------------------------------------- /src/pairp.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_PAIRP_H 21 | #define ELVEX_PAIRP_H 22 | 23 | #include "facade.hpp" 24 | #include "serializable.hpp" 25 | #include "variableflag.hpp" 26 | #include "shared_ptr.hpp" 27 | 28 | #ifdef OUTPUT_XML 29 | #include 30 | #endif 31 | 32 | class Pairp : public Facade, 33 | public Serializable, 34 | public std::enable_shared_from_this 35 | { 36 | 37 | public: 38 | enum Type 39 | { 40 | _ATOM_, 41 | _PAIRP_, 42 | _NIL_ 43 | }; 44 | static pairpPtr NIL; 45 | 46 | private: 47 | enum Type type; 48 | valuePtr value; 49 | struct 50 | { 51 | pairpPtr car; 52 | pairpPtr cdr; 53 | } pairp; 54 | 55 | void makeSerialString(void); 56 | 57 | VariableFlag variableFlag; 58 | 59 | static pairpPtr create(void); 60 | 61 | public: 62 | Pairp(enum Type, valuePtr = valuePtr(), pairpPtr = pairpPtr(), pairpPtr = pairpPtr()); 63 | 64 | ~Pairp(); 65 | 66 | static pairpPtr create(valuePtr); 67 | 68 | static pairpPtr create(pairpPtr, pairpPtr); 69 | 70 | Type getType(void) const; 71 | 72 | void setType(Type); 73 | 74 | valuePtr getValue(void) const; 75 | 76 | void setValue(valuePtr); 77 | 78 | pairpPtr getCar(void) const; 79 | 80 | pairpPtr getCdr(void) const; 81 | 82 | bool isNil(void) const; 83 | 84 | bool isAtom(void) const; 85 | 86 | bool isVariable(void) const; 87 | 88 | bool isPairp(void) const; 89 | 90 | void print(std::ostream &) const; 91 | 92 | void flatPrint(std::ostream &, bool) const; 93 | 94 | bool buildEnvironment(statementPtr statement, const environmentPtr &environment, const pairpPtr &otherPairp, bool acceptToFilterNULLVariables, bool root, bool verbose); 95 | 96 | void deleteVariables(void); 97 | 98 | void deleteAnonymousVariables(void); 99 | 100 | bool renameVariables(uint32_t); 101 | 102 | void apply(statementPtr from, class Item *item, class Parser &parser, class Generator *generator, uint32_t code, statementPtr statement, 103 | bool &effect, bool verbose); 104 | 105 | #ifdef OUTPUT_XML 106 | void toXML(xmlNodePtr); 107 | #endif 108 | 109 | pairpPtr clone(void) const; 110 | 111 | void enable(const statementPtr &, class Item *, class Generator *generator, bool &, bool); 112 | 113 | bool subsumes(statementPtr from, const pairpPtr &, const environmentPtr &, bool verbose); 114 | 115 | pairpPtr pushFront(valuePtr); 116 | 117 | pairpPtr pushBack(valuePtr); 118 | 119 | bool containsVariable(void); 120 | 121 | bool findVariable(uint32_t key) const; 122 | 123 | void setVariableFlag(enum VariableFlag::flagValues); 124 | }; 125 | 126 | #endif // ELVEX_PAIRP_H 127 | -------------------------------------------------------------------------------- /src/parser.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_PARSER_H 21 | #define ELVEX_PARSER_H 22 | 23 | #include 24 | #include 25 | #include "shared_ptr.hpp" 26 | #include "rules.hpp" 27 | #include "entry.hpp" 28 | #include "entries.hpp" 29 | #include "features.hpp" 30 | 31 | class Parser 32 | { 33 | 34 | public: 35 | typedef std::unordered_map entry_map; 36 | 37 | typedef std::unordered_map entries_map; 38 | 39 | // POS => (LEMMA => ENTRY) 40 | // i.e.: verb => (MANGER => (mangions[…], mange|mange[…])) 41 | typedef std::unordered_map entries_map_map; 42 | 43 | // macro => featuresPtr 44 | typedef std::unordered_map macro_map; 45 | 46 | private: 47 | Rules rules; 48 | entries_map_map cacheLexicon; 49 | entry_map mapLocalEntry; 50 | macro_map macros; 51 | featuresPtr startFeatures; 52 | uint32_t startTerm; 53 | bool verbose; 54 | featuresPtr localFeatures; 55 | std::deque bufferNames; 56 | std::deque linenos; 57 | 58 | public: 59 | Parser(); 60 | 61 | ~Parser(); 62 | 63 | void pushBufferName(std::string); 64 | 65 | std::string popBufferName(); 66 | 67 | void pushLineno(uint32_t); 68 | 69 | uint32_t popLineno(); 70 | 71 | uint32_t getTopLineno(); 72 | 73 | class Rules &getRules(); 74 | 75 | std::string getTopBufferName(); 76 | 77 | uint32_t getStartTerm() const; 78 | 79 | void setStartTerm(uint32_t); 80 | 81 | void setStartFeatures(featuresPtr); 82 | 83 | featuresPtr getStartFeatures() const; 84 | 85 | featuresPtr getLocalFeatures() const; 86 | 87 | void setLocalFeatures(featuresPtr); 88 | 89 | void insertCacheLexicon(std::pair); 90 | 91 | entries_map_map::const_iterator findCacheLexicon(uint32_t) const; 92 | 93 | entries_map_map::const_iterator cbeginCacheLexicon() const; 94 | 95 | entries_map_map::const_iterator cendCacheLexicon() const; 96 | 97 | void printCacheLexicon(std::ostream &) const; 98 | 99 | void setVerbose(bool); 100 | 101 | bool getVerbose() const; 102 | 103 | entry_map::const_iterator findMapLocalEntry(std::string &) const; 104 | 105 | entry_map::const_iterator cendMapLocalEntry() const; 106 | 107 | void insertMapLocalEntry(std::pair); 108 | 109 | void addMacros(std::string, featuresPtr); 110 | 111 | featuresPtr findMacros(const std::string &); 112 | 113 | void parseFile(std::string prefix, std::string suffix, std::string fileName); 114 | 115 | void parseBuffer(std::string prefix, std::string suffix, std::string buffer, std::string bufferName); 116 | 117 | void printMacros(); 118 | 119 | private: 120 | void parseString(std::string buffer); 121 | }; 122 | 123 | #endif // ELVEX_PARSER_H 124 | -------------------------------------------------------------------------------- /src/compacted-lexicon-fsa.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include 21 | #include 22 | #include "compacted-lexicon-fsa.hpp" 23 | 24 | /* ************************************************** 25 | * 26 | ************************************************** */ 27 | CompactedLexiconFsa::CompactedLexiconFsa(uint32_t child, uint32_t next, 28 | uint32_t info, 29 | char character) 30 | { 31 | this->child = child; 32 | this->next = next; 33 | this->info = info; 34 | this->character = character; 35 | } 36 | 37 | /* ************************************************** 38 | * 39 | ************************************************** */ 40 | CompactedLexiconFsa::CompactedLexiconFsa(void) 41 | { 42 | this->child = (uint32_t)~0UL; 43 | this->next = (uint32_t)~0UL; 44 | this->info = (uint32_t)~0UL; 45 | this->character = (char)~0; 46 | } 47 | 48 | /* ************************************************** 49 | * 50 | ************************************************** */ 51 | void CompactedLexiconFsa::print(std::ostream &out) const 52 | { 53 | out << (long int)child << ' ' << (long int)next << ' ' << (long int)info << ' ' << (int)character 54 | << std::endl; 55 | } 56 | 57 | /* ************************************************** 58 | * 59 | ************************************************** */ 60 | bool CompactedLexiconFsa::hasChild() const 61 | { 62 | return child != (uint32_t)(~0UL); 63 | } 64 | 65 | /* ************************************************** 66 | * 67 | ************************************************** */ 68 | bool CompactedLexiconFsa::hasNext() const 69 | { 70 | return next != (uint32_t)(~0UL); 71 | } 72 | 73 | /* ************************************************** 74 | * 75 | ************************************************** */ 76 | bool CompactedLexiconFsa::hasInfo() const 77 | { 78 | return info != (uint32_t)(~0UL); 79 | } 80 | 81 | /* ************************************************** 82 | * 83 | ************************************************** */ 84 | uint32_t CompactedLexiconFsa::getChild(void) const 85 | { 86 | return child; 87 | } 88 | 89 | /* ************************************************** 90 | * 91 | ************************************************** */ 92 | uint32_t CompactedLexiconFsa::getNext() const 93 | { 94 | return next; 95 | } 96 | 97 | /* ************************************************** 98 | * 99 | ************************************************** */ 100 | uint32_t CompactedLexiconFsa::getInfo(void) const 101 | { 102 | return info; 103 | } 104 | 105 | /* ************************************************** 106 | * 107 | ************************************************** */ 108 | bool CompactedLexiconFsa::equalsThisChar(char _character) const 109 | { 110 | return this->character == _character; 111 | } 112 | -------------------------------------------------------------------------------- /src/flags.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include 21 | #include "flags.hpp" 22 | #include "messages.hpp" 23 | 24 | const std::bitset Flags::SEEN = std::bitset(1ul << 1u); 25 | const std::bitset Flags::XML = std::bitset(1ul << 2u); 26 | const std::bitset Flags::GENERATED = std::bitset(1ul << 3u); 27 | const std::bitset Flags::DISABLED = std::bitset(1ul << 4u); 28 | const std::bitset Flags::NIL = std::bitset(1ul << 5u); 29 | const std::bitset Flags::BOTTOM = std::bitset(1ul << 6u); 30 | const std::bitset Flags::CHOOSEN = std::bitset(1ul << 7u); 31 | const std::bitset Flags::REJECTED = std::bitset(1ul << 8u); 32 | 33 | /* ************************************************** 34 | * 35 | ************************************************** */ 36 | Flags::Flags() 37 | { 38 | this->flags = 0; 39 | } 40 | 41 | /* ************************************************** 42 | * 43 | ************************************************** */ 44 | Flags::Flags(const std::bitset &flags) 45 | { 46 | this->flags = flags; 47 | } 48 | 49 | /* ************************************************** 50 | * 51 | ************************************************** */ 52 | std::bitset &Flags::getFlags() 53 | { 54 | return this->flags; 55 | } 56 | 57 | /* ************************************************** 58 | * 59 | ************************************************** */ 60 | bool Flags::isSet(const std::bitset &cmp) const 61 | { 62 | return (this->flags & cmp).any(); 63 | } 64 | 65 | /* ************************************************** 66 | * 67 | ************************************************** */ 68 | bool Flags::isUnset(const std::bitset &cmp) const 69 | { 70 | return (this->flags & cmp).none(); 71 | } 72 | 73 | /* ************************************************** 74 | * 75 | ************************************************** */ 76 | void Flags::add(const std::bitset &_flags) 77 | { 78 | this->flags |= _flags; 79 | } 80 | 81 | /* ************************************************** 82 | * 83 | ************************************************** */ 84 | void Flags::sub(const std::bitset &_flags) 85 | { 86 | this->flags &= ~_flags; 87 | } 88 | 89 | /* ************************************************** 90 | * 91 | ************************************************** */ 92 | void Flags::print(std::ostream &outStream) const 93 | { 94 | if (isSet(Flags::SEEN)) 95 | outStream << "SEEN "; 96 | if (isSet(XML)) 97 | outStream << "XML "; 98 | if (isSet(GENERATED)) 99 | outStream << "GENERATED "; 100 | if (isSet(DISABLED)) 101 | outStream << "DISABLED "; 102 | if (isSet(NIL)) 103 | outStream << "NIL "; 104 | if (isSet(BOTTOM)) 105 | outStream << "BOTTOM "; 106 | if (isSet(CHOOSEN)) 107 | outStream << "CHOOSEN "; 108 | if (isSet(REJECTED)) 109 | outStream << "REJECTED "; 110 | } 111 | -------------------------------------------------------------------------------- /src/postedition_fr.l: -------------------------------------------------------------------------------- 1 | %{ 2 | /* ************************************************** 3 | * 4 | * ELVEX 5 | * 6 | * Copyright 2014-2023 LABRI, 7 | * CNRS (UMR 5800), the University of Bordeaux, 8 | * and the Bordeaux INP 9 | * 10 | * Author: 11 | * Lionel Clément 12 | * LaBRI - Université Bordeaux 13 | * 351, cours de la Libération 14 | * 33405 Talence Cedex - France 15 | * lionel.clement@u-bordeaux.fr 16 | * 17 | * This file is part of ELVEX. 18 | * 19 | ************************************************** */ 20 | 21 | // 22 | // Morphological transformation for French Language 23 | // 24 | 25 | #include 26 | #define YY_NO_INPUT 27 | 28 | %} 29 | 30 | %option noyywrap 31 | 32 | %s NEXT BEGINLINE 33 | 34 | weakPonct [,;:()'-] 35 | strongPonct [.!?/] 36 | mesure mm|cm|m|dm|km|m2|m3|A|[oO]hm|V|VA|gr|[kK]g 37 | 38 | %% 39 | 40 | { 41 | [ \t]+ ; 42 | [[:lower:]] { 43 | char cpy = *yytext; 44 | unput(toupper(cpy)); 45 | BEGIN(BEGINLINE); 46 | } 47 | . {yyless(0); BEGIN(BEGINLINE);} 48 | } 49 | 50 | . {yyless(0); unput(' '); BEGIN(NEXT);} 51 | 52 | { 53 | \./[^0-9+-] {ECHO; BEGIN(INITIAL);} 54 | [[:space:]][nNdDjJlL][ea][[:space:]]+/[hH]?([aAeEiIoOuUyY]|â|Â|à|À|é|É|è|È|ê|Ê|ë|Ë|î|Î|ï|Ï|ö|Ö|ô|Ô|ü|Ü|û|Û) {std::cout << yytext[0] << yytext[1] << '\'';} 55 | [[:space:]][mMtTsS][e][[:space:]]+/[hH]?([aAeEiIoOuUyY]|â|Â|à|À|é|É|è|È|ê|Ê|ë|Ë|î|Î|ï|Ï|ö|Ö|ô|Ô|ü|Ü|û|Û) {std::cout << yytext[0] << yytext[1] << '\'';} 56 | [[:space:]][mMtTsS][a][[:space:]]+/[hH]?([aAeEiIoOuUyY]|â|Â|à|À|é|É|è|È|ê|Ê|ë|Ë|î|Î|ï|Ï|ö|Ö|ô|Ô|ü|Ü|û|Û) {std::cout << yytext[0] << yytext[1] << "on ";} 57 | [[:space:]][qQ]ue[[:space:]]+/[hH]?([aAeEiIoOuUyY]|â|Â|à|À|é|É|è|È|ê|Ê|ë|Ë|î|Î|ï|Ï|ö|Ö|ô|Ô|ü|Ü|û|Û) {std::cout << yytext[0] << "qu'";} 58 | [[:space:]][bB]eau[[:space:]]+[aeiouy] {std::cout << yytext[0] << yytext[1] << yytext[2] << "l " << yytext[yyleng-1];} 59 | [[:space:]][cC]e[[:space:]]+[aeiouy] {std::cout << yytext[0] << yytext[1] << "et " << yytext[yyleng-1];} 60 | [[:space:]][cC]e[[:space:]]+(é|è|ê|ë|î|ï|ô|ö|ù) {std::cout << yytext[0] << yytext[1] << "et " << yytext[yyleng-2] << yytext[yyleng-1];} 61 | [[:space:]][cC]e[[:space:]]+[hH][aeiouy] {std::cout << yytext[0] << yytext[1] << "et " << yytext[yyleng-2] << yytext[yyleng-1];} 62 | [[:space:]][cC]e[[:space:]]+[hH](é|è|ê|ë|î|ï|ô|ö|ù) {std::cout << yytext[0] << yytext[1] << "et " << yytext[yyleng-3] << yytext[yyleng-2] << yytext[yyleng-1];} 63 | [[:space:]][dD]e[[:space:]]+les/([[:space:]]+|quel) {std::cout << yytext[0] << yytext[1] << "es";} 64 | [[:space:]](à|À)[[:space:]]+les/([[:space:]]+|quel) {std::cout << yytext[0] << "aux";} 65 | [[:space:]][dD]e[[:space:]]+le/([[:space:]]+|quel) {std::cout << yytext[0] << yytext[1] << 'u';} 66 | [[:space:]](à|À)[[:space:]]+le/[[:space:]]+ {std::cout << yytext[0] << "au";} 67 | [[:space:]](à|À)[[:space:]]+le/quel {std::cout << yytext[0] << "au";} 68 | [[:space:]](à|À)[[:space:]]+l[ea][[:space:]]+[hH]?/([aAeEiIoOuUyY]|â|Â|à|À|é|É|è|È|ê|Ê|ë|Ë|î|Î|ï|Ï|ö|Ö|ô|Ô|ü|Ü|û|Û) {std::cout << yytext[0] << "à l'";} 69 | [[:space:]][sS]i[[:space:]]+[i] {std::cout << yytext[0] << yytext[1] << '\'' << yytext[yyleng-1];} 70 | [[:space:]][dD]e[[:space:]]+des/[[:space:]]+ {std::cout << yytext[0] << yytext[1] << 'e';} 71 | [[:space:]][dD]e[[:space:]]+l[ea][[:space:]]+[hH]?/([aAeEiIoOuUyY]|â|Â|à|À|é|É|è|È|ê|Ê|ë|Ë|î|Î|ï|Ï|ö|Ö|ô|Ô|ü|Ü|û|Û) {std::cout << yytext[0] << "de l'";} 72 | [[:digit:]][[:space:]]+/{mesure}[[:space:]]+ {yytext[yyleng-1]=0; ECHO;} 73 | [-][[:space:]]+ {yytext[yyleng-1]=0; ECHO;} 74 | [ \t]+/[,.;:-] {} 75 | \n {ECHO; BEGIN(INITIAL);} 76 | . {ECHO;} 77 | } 78 | 79 | %% 80 | 81 | int main(){ 82 | yylex(); 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /src/features.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_FEATURES_H 21 | #define ELVEX_FEATURES_H 22 | 23 | #include 24 | 25 | #ifdef OUTPUT_XML 26 | #include 27 | #endif 28 | 29 | #include "facade.hpp" 30 | #include "serializable.hpp" 31 | #include "shared_ptr.hpp" 32 | #include "variableflag.hpp" 33 | 34 | class Features : public Facade, 35 | public Serializable, 36 | public std::enable_shared_from_this 37 | { 38 | 39 | public: 40 | static featuresPtr NIL; 41 | 42 | static featuresPtr BOTTOM; 43 | 44 | typedef std::vector list_of_feature; 45 | 46 | private: 47 | list_of_feature features; 48 | 49 | uint32_t head; 50 | 51 | std::string form; 52 | 53 | VariableFlag variableFlag; 54 | 55 | static featuresPtr createBottom(); 56 | 57 | static featuresPtr createNil(); 58 | 59 | void makeSerialString(); 60 | 61 | public: 62 | Features(const featurePtr &); 63 | 64 | ~Features(); 65 | 66 | static featuresPtr create(const featurePtr & = featurePtr()); 67 | 68 | void putId(unsigned int id); 69 | 70 | void add(const featurePtr &); 71 | 72 | void add(const featuresPtr &); 73 | 74 | size_t size() const; 75 | 76 | list_of_feature::const_iterator cbegin() const; 77 | 78 | list_of_feature::const_iterator cend() const; 79 | 80 | list_of_feature::iterator begin(); 81 | 82 | list_of_feature::iterator end(); 83 | 84 | list_of_feature::iterator erase(list_of_feature::iterator); 85 | 86 | featurePtr front() const; 87 | 88 | void print(std::ostream &) const; 89 | 90 | void flatPrint(std::ostream &, bool par = true) const; 91 | 92 | #ifdef OUTPUT_XML 93 | void toXML(xmlNodePtr); 94 | #endif 95 | 96 | featuresPtr clone() const; 97 | 98 | valuePtr find(const bitsetPtr &) const; 99 | 100 | bool buildEnvironment(statementPtr statementRoot, const environmentPtr &, const featuresPtr &, bool 101 | #ifdef TRACE_BUILD_ENVIRONMENT 102 | , 103 | bool 104 | #endif 105 | , bool verbose); 106 | 107 | void subFlags(const std::bitset &); 108 | 109 | uint32_t assignHead(); 110 | 111 | std::string *assignForm(); 112 | 113 | bool renameVariables(uint32_t); 114 | 115 | bool isNil() const; 116 | 117 | bool isBottom() const; 118 | 119 | void enable(statementPtr statementRoot, class Item *, class Generator *synthesizer, bool &, bool); 120 | 121 | bool subsumes(statementPtr statementRoot, const featuresPtr &, const environmentPtr &, bool verbose); 122 | 123 | void deleteAnonymousVariables(); 124 | 125 | void deleteVariables(); 126 | 127 | bool containsVariable(); 128 | 129 | bool findVariable(uint32_t key) const; 130 | 131 | void setVariableFlag(enum VariableFlag::flagValues flag); 132 | 133 | void apply(statementPtr statementRoot, class Item *item, class Parser &parser, Generator *synthesizer, const statementPtr &variable, 134 | const statementPtr &body, 135 | bool &effect, bool verbose); 136 | }; 137 | 138 | #endif // ELVEX_FEATURES_H 139 | -------------------------------------------------------------------------------- /src/rule.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_RULE_H 21 | #define ELVEX_RULE_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #ifdef OUTPUT_XML 28 | #include 29 | #endif 30 | 31 | #include "facade.hpp" 32 | #include "shared_ptr.hpp" 33 | 34 | class Rule : public Facade, 35 | public Serializable, 36 | public std::enable_shared_from_this 37 | { 38 | 39 | private: 40 | uint32_t lhs; 41 | std::vector rhs; 42 | statementsPtr statements; 43 | uint32_t usages; 44 | std::string filename; 45 | uint32_t lineno; 46 | bool trace; 47 | bool withSpaces; 48 | bool bidirectional; 49 | bool permutable; 50 | 51 | void makeSerialString(void); 52 | 53 | public: 54 | static rulePtr create(uint32_t id, uint32_t lineno, std::string filename, bool withSpaces, bool bidirectional, bool permutable, uint32_t lhs, 55 | statementsPtr statements = statementsPtr()); 56 | 57 | static rulePtr 58 | create(uint32_t lineno, std::string filename, bool withSpaces, bool bidirectional, bool permutable, uint32_t lhs, statementsPtr statements = statementsPtr()); 59 | 60 | static rulePtr create(uint32_t lineno, std::string filename, bool withSpaces, bool bidirectional, bool permutable, uint32_t lhs, std::vector &rhs, 61 | statementsPtr statements = statementsPtr()); 62 | 63 | static rulePtr create(uint32_t id, uint32_t lineno, std::string filename, bool withSpaces, bool bidirectional, bool permutable, uint32_t lhs, std::vector &rhs, 64 | statementsPtr statements = statementsPtr()); 65 | 66 | Rule(uint32_t id, uint32_t lineno, std::string filename, bool withSpaces, bool bidirectional, bool permutable, uint32_t lhs, statementsPtr statements = statementsPtr()); 67 | 68 | Rule(uint32_t lineno, std::string filename, bool withSpaces, bool bidirectional, bool permutable, uint32_t lhs, statementsPtr statements = statementsPtr()); 69 | 70 | Rule(uint32_t lineno, std::string filename, bool withSpaces, bool bidirectional, bool permutable, uint32_t lhs, std::vector &rhs, 71 | statementsPtr statements = statementsPtr()); 72 | 73 | Rule(uint32_t id, uint32_t lineno, std::string filename, bool withSpaces, bool bidirectional, bool permutable, uint32_t lhs, std::vector &rhs, 74 | statementsPtr statements = statementsPtr()); 75 | 76 | ~Rule(); 77 | 78 | uint32_t getLhs(void) const; 79 | 80 | std::vector &getRhs(void); 81 | 82 | //uint32_t getCurrentTerm(void) const; 83 | 84 | //termsPtr getCurrentTerms() const; 85 | 86 | termsPtr getTerms(size_t) const; 87 | 88 | //void setCurrentTerms(termsPtr); 89 | 90 | statementsPtr getStatements(void) const; 91 | 92 | void incUsages(class Generator *); 93 | 94 | void resetUsages(void); 95 | 96 | uint32_t getLineno(void); 97 | 98 | bool getWithSpaces(void) const; 99 | 100 | bool getBidirectional(void) const; 101 | 102 | bool getPermutable(void) const; 103 | 104 | const std::string &getFilename(void) const; 105 | 106 | bool getTrace(void) const; 107 | 108 | void setTrace(bool trace); 109 | 110 | rulePtr clone() const; 111 | 112 | void print(std::ostream &, uint8_t index = UINT8_MAX, bool withSemantic = false, bool html = true) const; 113 | 114 | std::string toString() const; 115 | 116 | #ifdef OUTPUT_XML 117 | void toXML(xmlNodePtr); 118 | #endif 119 | 120 | }; 121 | 122 | #endif // ELVEX_RULE_H 123 | -------------------------------------------------------------------------------- /src/entry.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "messages.hpp" 29 | #include "entry.hpp" 30 | #include "features.hpp" 31 | #include "value.hpp" 32 | #include "vartable.hpp" 33 | #include "shared_ptr.hpp" 34 | 35 | /* ************************************************** 36 | * 37 | ************************************************** */ 38 | Entry::Entry(const std::string &form, featuresPtr features) 39 | { 40 | this->form = form; 41 | this->features = features; 42 | NEW; 43 | } 44 | 45 | /* ************************************************** 46 | * 47 | ************************************************** */ 48 | Entry::Entry(featuresPtr features) 49 | { 50 | this->form = ""; 51 | this->features = features; 52 | NEW; 53 | } 54 | 55 | /* ************************************************** 56 | * 57 | ************************************************** */ 58 | Entry::~Entry() 59 | { 60 | DELETE; 61 | if (features) 62 | features.reset(); 63 | } 64 | 65 | /* ************************************************** 66 | * 67 | ************************************************** */ 68 | entryPtr Entry::create(const std::string &form, featuresPtr features) 69 | { 70 | return std::make_shared(form, features); 71 | } 72 | 73 | /* ************************************************** 74 | * 75 | ************************************************** */ 76 | entryPtr Entry::create(featuresPtr features) 77 | { 78 | return std::make_shared(features); 79 | } 80 | 81 | /* ************************************************** 82 | * 83 | ************************************************** */ 84 | std::string &Entry::getForm() 85 | { 86 | return form; 87 | } 88 | 89 | /* ************************************************** 90 | * 91 | ************************************************** */ 92 | featuresPtr Entry::getFeatures() const 93 | { 94 | return features; 95 | } 96 | 97 | #ifdef OUTPUT_XML 98 | /* ************************************************** 99 | * 100 | ************************************************** */ 101 | void Entry::toXML(xmlNodePtr nodeRoot) const 102 | { 103 | xmlNodePtr entry = xmlNewChild(nodeRoot, nullptr, (const xmlChar *)"ENTRY", nullptr); 104 | if (!this->form.empty()) 105 | { 106 | xmlSetProp(entry, (xmlChar *)"form", (xmlChar *)this->form.c_str()); 107 | } 108 | if (this->features) 109 | { 110 | this->features->toXML(entry); 111 | } 112 | } 113 | #endif 114 | 115 | /* ************************************************** 116 | * 117 | ************************************************** */ 118 | void Entry::print(std::ostream &os) const 119 | { 120 | os << "Entry(" /*<< Vartable::codeToName(this->pos) */; 121 | if (!this->form.empty()) 122 | os << "form:\"" << this->form << "\", "; 123 | if (features) 124 | { 125 | features->flatPrint(os); 126 | } 127 | else 128 | { 129 | FATAL_ERROR_UNEXPECTED; 130 | } 131 | os << ')'; 132 | } 133 | 134 | /* ************************************************** 135 | * 136 | ************************************************** */ 137 | void Entry::makeSerialString() 138 | { 139 | std::ostringstream stream; 140 | stream << form << '/'; 141 | if (features) 142 | stream << features->peekSerialString(); 143 | else 144 | stream << '/'; 145 | serialString = stream.str(); 146 | } 147 | 148 | /* ************************************************** 149 | * 150 | ************************************************** */ 151 | entryPtr Entry::clone() const 152 | { 153 | return create(std::string(form), features->clone()); 154 | } 155 | 156 | /* ************************************************** 157 | * 158 | ************************************************** */ 159 | void Entry::renameVariables(uint32_t code) 160 | { 161 | features->renameVariables(code); 162 | } 163 | -------------------------------------------------------------------------------- /src/entries.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include 21 | #include "messages.hpp" 22 | #include "entries.hpp" 23 | #include "entry.hpp" 24 | 25 | /* ************************************************** 26 | * 27 | ************************************************** */ 28 | Entries::Entries() 29 | { 30 | NEW; 31 | } 32 | 33 | /* ************************************************** 34 | * 35 | ************************************************** */ 36 | Entries::Entries(const entryPtr &entry) 37 | { 38 | this->entries.insert(this->entries.begin(), entry); 39 | NEW; 40 | } 41 | 42 | /* ************************************************** 43 | * 44 | ************************************************** */ 45 | Entries::Entries(const std::vector &entries) 46 | { 47 | this->entries = entries; 48 | NEW; 49 | } 50 | 51 | /* ************************************************** 52 | * 53 | ************************************************** */ 54 | Entries::~Entries() 55 | { 56 | for (auto tmp : entries) 57 | { 58 | if (tmp) 59 | tmp.reset(); 60 | } 61 | DELETE; 62 | } 63 | 64 | /* ************************************************** 65 | * 66 | ************************************************** */ 67 | entriesPtr Entries::create() 68 | { 69 | return std::make_shared(); 70 | } 71 | 72 | /* ************************************************** 73 | * 74 | ************************************************** */ 75 | entriesPtr Entries::create(const entryPtr &entry) 76 | { 77 | return std::make_shared(entry); 78 | } 79 | 80 | /* ************************************************** 81 | * 82 | ************************************************** */ 83 | entriesPtr Entries::create(const std::vector &entries) 84 | { 85 | return std::make_shared(entries); 86 | } 87 | 88 | /* ************************************************** 89 | * 90 | ************************************************** */ 91 | size_t Entries::size() const 92 | { 93 | return this->entries.size(); 94 | } 95 | 96 | /* ************************************************** 97 | * 98 | ************************************************** */ 99 | std::vector::iterator Entries::begin() 100 | { 101 | return entries.begin(); 102 | } 103 | 104 | /* ************************************************** 105 | * 106 | ************************************************** */ 107 | std::vector::iterator Entries::end() 108 | { 109 | return entries.end(); 110 | } 111 | 112 | /* ************************************************** 113 | * 114 | ************************************************** */ 115 | void Entries::add(const entryPtr &entry) 116 | { 117 | this->entries.push_back(entry); 118 | } 119 | 120 | /* ************************************************** 121 | * 122 | ************************************************** */ 123 | void Entries::add(entriesPtr entries) 124 | { 125 | for (auto entry : *entries) 126 | { 127 | this->entries.push_back(entry); 128 | } 129 | } 130 | 131 | /* ************************************************** 132 | * 133 | ************************************************** */ 134 | entryPtr Entries::get(unsigned int i) const 135 | { 136 | return this->entries.at(i); 137 | } 138 | 139 | #ifdef OUTPUT_XML 140 | /* ************************************************** 141 | * 142 | ************************************************** */ 143 | void Entries::toXML(xmlNodePtr nodeRoot) const 144 | { 145 | xmlNodePtr node = xmlNewChild(nodeRoot, nullptr, (const xmlChar *)"ENTRIES", nullptr); 146 | for (const auto &entrie : entries) 147 | entrie->toXML(node); 148 | } 149 | #endif 150 | 151 | /* ************************************************** 152 | * 153 | ************************************************** */ 154 | void Entries::print(std::ostream &out) const 155 | { 156 | bool first = true; 157 | for (const auto &i : entries) 158 | { 159 | if (first) 160 | first = false; 161 | else 162 | out << '|'; 163 | i->print(out); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /test/test-En.pattern: -------------------------------------------------------------------------------- 1 | // @macro features 2 | // lexeme pos lemma features 3 | 4 | // *********************************************************** 5 | // Macros 6 | // ***********************************************************/ 7 | 8 | EUPHORIC verb TO_BE [SUBJECT:[@hum],iiReal:VCOMP|SCOMP,PRED_ADJ:[FORM:"over the moon"]] 9 | EUPHORIC verb TO_BE [SUBJECT:[@hum],iiReal:VCOMP|SCOMP,PRED_ADJ:[HEAD:HAPPY,MOD:<[HEAD:EXTREMELY]>]] 10 | EUPHORIC verb TO_BE [SUBJECT:[@hum],iiReal:VCOMP|SCOMP,PRED_ADJ:[HEAD:THRILLED]] 11 | 12 | PRIVILEGE verb TO_HAVE [SUBJECT:[@hum],iiReal:VCOMP,OBLIQUE:[HEAD:PRIVILEGE, @s, @def]] 13 | PRIVILEGE verb TO_HAVE [SUBJECT:[@hum],iiReal:VCOMP,OBLIQUE:[HEAD:OPPORTUNITY, @s, @def]] 14 | PRIVILEGE verb TO_BE [SUBJECT:[@hum],iiReal:VCOMP|SCOMP,PRED_ADJ:[HEAD:LUCKY]] 15 | PRIVILEGE verb TO_BE [SUBJECT:[@hum],iiReal:VCOMP|SCOMP,PRED_ADJ:[HEAD:BLESSED]] 16 | PRIVILEGE verb TO_BE [SUBJECT:[@hum],iiReal:VCOMP|SCOMP,PRED_ADJ:[FORM:"in a position"]] 17 | PRIVILEGE verb TO_BE [SUBJECT:[@hum],iiReal:VCOMP,PRED_ADJ:[FORM:"able"]] 18 | 19 | TO_CHASE verb TO_CHASE [iiReal:OBJECT] 20 | TO_FIND_OUT verb TO_FIND [particule:_out_,iiReal:SCOMP,compl:_that_] 21 | TO_STUDY verb TO_STUDY [SUBJECT:[@hum],iiReal:OBJECT] 22 | TO_MEOW verb TO_MEOW [] 23 | TO_ACCEPT verb TO_ACCEPT [iiReal:OBJECT|VCOMP|SCOMP,compl:_that_] 24 | 25 | TO_FEEL verb TO_FEEL [HEAD:TO_FEEL,SUBJECT:[@hum],iiReal:PRED_ADJ|SCOMP|OBJECT|OBJ_THETA,pcase:_at_,compl:_that_|_if_] 26 | 27 | TO_FEEL_THE_PAIN TO_FEEL verb [iiReal:OBJECT,OBJECT:[HEAD:PAIN,@def,@s]] 28 | TO_FEEL_BLUE verb TO_FEEL [iiReal:PRED_ADJ,PRED_ADJ:[HEAD:BLUE]] 29 | 30 | TO_APPRECIATE verb TO_APPRECIATE [SUBJECT:[@hum],iiReal:OBJECT] 31 | 32 | TO_ENJOY verb TO_ENJOY [SUBJECT:[@hum],iiReal:OBJECT] 33 | TO_SUFFER verb TO_SUFFER [SUBJECT:[@hum],iiReal:OBJECT] 34 | TO_ENDURE verb TO_ENDURE [SUBJECT:[@hum],iiReal:OBJECT] 35 | 36 | TO_USE verb TO_USE [SUBJECT:[@hum],iiReal:OBJECT] 37 | 38 | TO_STAY_AWAY verb TO_STAY_AWAY [SUBJECT:[@hum]] 39 | 40 | // To CALL 41 | // to call someone/something 42 | TO_CALL verb TO_CALL [SUBJECT:[@hum],iiReal:OBJECT] 43 | // to call someone down : to reprimand a person 44 | TO_CALL_DOWN_1 verb TO_CALL [SUBJECT:[@hum],iiReal:OBJECT,OBJECT:[@hum],particule:_down_] 45 | // to call something down to someone: to shout something to a person on a lower level 46 | TO_CALL_DOWN_2 verb TO_CALL [SUBJECT:[@hum],iiReal:OBJECT,OBJECT:[human:false],iiiReal:OBJ_THETA,pcase:_to_,particule:_down_] 47 | // to call something down on someone: to invoke some sort of divine punishment onto someone 48 | TO_CALL_DOWN_3 verb TO_CALL [SUBJECT:[@hum],iiReal:OBJECT,OBJECT:[human:false],iiiReal:OBJ_THETA,pcase:_on_,particule:_down_] 49 | 50 | TO_SNORE verb TO_SNORE [SUBJECT:[animate:true]] 51 | 52 | TO_SIT verb TO_SIT [iiReal:OBJ_THETA,pcase:_on_] 53 | 54 | TO_SAY verb TO_SAY [iiReal:SCOMP,compl:_that_] 55 | 56 | TO_WANT verb TO_WANT [SUBJECT:[],iiReal:VCOMP,VCOMP:[]] 57 | 58 | TO_TELL verb TO_TELL [SUBJECT:[@hum],iiReal:OBJECT,iiiReal:SCOMP,ii_csu:_that_] 59 | 60 | 61 | //////// 62 | // To put on the brakes: to describe the act of slowing down or stopping something, especially a vehicle, in a sudden or emergency situation. 63 | // To hit the brakes: to suddenly stop or slow down, especially in a vehicle 64 | // To pump the brakes: to apply and release the brakes repeatedly, as a way of slowing down a vehicle without skidding or losing control 65 | // To step on the brakes: to press down on the brake pedal in a vehicle, as a way of slowing down or stopping 66 | //////// 67 | 68 | 69 | //Nouns 70 | PAIN common_noun PAIN [countable:false] 71 | SADNESS common_noun SADNESS [countable:false] 72 | HOPE common_noun HOPE [countable:false] 73 | TENDERNESS common_noun TENDERNESS [countable:false] 74 | WARNING common_noun WARNING [] 75 | DIVINE_BLESSINGS common_noun DIVINE_BLESSINGS [] 76 | CHAIR common_noun CHAIR [] 77 | CHAIR_MAN common_noun CHAIR_MAN [] 78 | MOON common_noun MOON [] 79 | STUDENT common_noun STUDENT [] 80 | PROFESSOR common_noun PROFESSOR [] 81 | CAT common_noun CAT [] 82 | MOUSE common_noun MOUSE [] 83 | TABLE common_noun TABLE [] 84 | PRIVILEGE common_noun PRIVILEGE [] 85 | OPPORTUNITY common_noun OPPORTUNITY [] 86 | 87 | // Adjectives 88 | THRILLED adj THRILLED [type:opinion] 89 | NICE adj NICE [type:opinion] 90 | BAD adj BAD [lexical_function:none,type:opinion] 91 | BAD adj BAD [lexical_function:magn,MOD:[HEAD:VERY],type:opinion] 92 | GOOD adj GOOD [type:opinion] 93 | HAPPY adj HAPPY [type:opinion] 94 | LUCKY adj LUCKY [type:opinion] 95 | BLESSED adj BLESSED [type:opinion] 96 | BLUE adj BLUE [type:color] 97 | BLACK adj BLACK [type:color] 98 | BIG adj BIG [type:size] 99 | 100 | // type:Opinion, Size, Age, Shape, Color, Origin, Material, Purpose/Qualifier 101 | // Adverbs 102 | VERY adv VERY [] 103 | EXTREMELY adv EXTREMELY [] 104 | // end -------------------------------------------------------------------------------- /src/value.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_VALUE_H 21 | #define ELVEX_VALUE_H 22 | 23 | #include "facade.hpp" 24 | #include "shared_ptr.hpp" 25 | #include "serializable.hpp" 26 | #include "variableflag.hpp" 27 | 28 | #ifdef OUTPUT_XML 29 | #include 30 | #endif 31 | 32 | class Value : public Facade, 33 | public Serializable, 34 | public std::enable_shared_from_this 35 | { 36 | 37 | public: 38 | enum Type 39 | { 40 | NIL_VALUE, 41 | TRUE_VALUE, 42 | FALSE_VALUE, 43 | CONSTANT_VALUE, 44 | VARIABLE_VALUE, 45 | ANONYMOUS_VALUE, 46 | IDENTIFIER_VALUE, 47 | FEATURES_VALUE, 48 | //LIST_FEATURES_VALUE, 49 | PAIRP_VALUE, 50 | NUMBER_VALUE, 51 | FORM_VALUE 52 | }; 53 | 54 | private: 55 | bitsetPtr bitset; // pour encoder les constantes 56 | uint32_t code; // pour encoder les identifiers et les variables 57 | pairpPtr pairp; 58 | std::string string; 59 | double number; 60 | VariableFlag variableFlag; 61 | featuresPtr features; // pour encoder les SF 62 | //listFeaturesPtr listFeatures; // pour encoder les listes de SF 63 | 64 | public: 65 | static valuePtr STATIC_NIL; 66 | static valuePtr STATIC_TRUE; 67 | static valuePtr STATIC_FALSE; 68 | static valuePtr STATIC_ANONYMOUS; 69 | 70 | Type type; 71 | 72 | private: 73 | Value(const enum Type, const std::string &); 74 | 75 | Value(const enum Type, uint32_t = 0, double = 0.0, bitsetPtr = bitsetPtr(), featuresPtr = featuresPtr(), 76 | pairpPtr = pairpPtr()/*, listFeaturesPtr = listFeaturesPtr()*/); 77 | 78 | void makeSerialString(void); 79 | 80 | public: 81 | ~Value(); 82 | 83 | static valuePtr createEmpty(const enum Type type); 84 | static valuePtr createNumber(double number); 85 | static valuePtr createVariable(uint32_t code); 86 | static valuePtr createIdentifier(uint32_t code); 87 | static valuePtr createIdentifier(const std::string &name); 88 | static valuePtr createForm(const std::string &str); 89 | static valuePtr createConstant(bitsetPtr bitset); 90 | static valuePtr createFeatures(featuresPtr features); 91 | static valuePtr createPairp(pairpPtr pairp); 92 | 93 | enum Type getType(void) const; 94 | 95 | bitsetPtr getBitset(void) const; 96 | 97 | uint32_t getCode(void) const; 98 | 99 | featuresPtr getFeatures(void) const; 100 | 101 | //listFeaturesPtr getListFeatures(void) const; 102 | 103 | double getNumber(void) const; 104 | 105 | std::string &getString(void) ; 106 | 107 | pairpPtr getPairp(void) const; 108 | 109 | void print(std::ostream &) const; 110 | 111 | void flatPrint(std::ostream &) const; 112 | 113 | #ifdef OUTPUT_XML 114 | void toXML(xmlNodePtr) const; 115 | #endif 116 | 117 | bool buildEnvironment(statementPtr statementRoot, const environmentPtr &environment, const valuePtr &value, bool acceptToFilterNULLVariables, bool root, bool verbose); 118 | 119 | bool subsumes(statementPtr statementRoot, const valuePtr &, const environmentPtr &, bool verbose); 120 | 121 | valuePtr clone(void); 122 | 123 | void deleteAnonymousVariables(void); 124 | 125 | void deleteVariables(void); 126 | 127 | bool renameVariables(uint32_t); 128 | 129 | bool isNil(void) const; 130 | 131 | bool isFalse(void) const; 132 | 133 | bool isTrue(void) const; 134 | 135 | bool isAnonymous(void) const; 136 | 137 | bool isNumber(void) const; 138 | 139 | bool isString(void) const; 140 | 141 | bool isVariable(void) const; 142 | 143 | bool isIdentifier(void) const; 144 | 145 | bool isFeatures(void) const; 146 | 147 | bool isConstant(void) const; 148 | 149 | bool isPairp(void) const; 150 | 151 | // bool isListFeatures(void) const; 152 | 153 | void enable(const statementPtr &root, class Item *item, class Generator *synthesizer, bool &effect, bool on); 154 | 155 | bool eq(valuePtr) const; 156 | 157 | bool lessThan(const valuePtr &) const; 158 | 159 | bool findVariable(uint32_t key) const; 160 | 161 | void apply(statementPtr statementRoot, class Item *item, class Parser &parser, class Generator *synthesizer, uint32_t variable, const statementPtr &body, 162 | bool &effect, bool verbose); 163 | 164 | bool containsVariable(void); 165 | 166 | void setVariableFlag(enum VariableFlag::flagValues flag); 167 | }; 168 | 169 | #endif // ELVEX_VALUE_H 170 | -------------------------------------------------------------------------------- /src/generator.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #ifndef ELVEX_GENERATOR_H 21 | #define ELVEX_GENERATOR_H 22 | 23 | #include 24 | 25 | #include "shared_ptr.hpp" 26 | #include "forestmap.hpp" 27 | #include "memoization-map.hpp" 28 | #include "parser.hpp" 29 | 30 | #ifndef MAXLENGTH 31 | #define MAXLENGTH 3000 32 | #endif 33 | 34 | #ifndef MAXUSAGES 35 | #define MAXUSAGES 3000 36 | #endif 37 | 38 | #ifndef MAXITEMS 39 | #define MAXITEMS 3000 40 | #endif 41 | 42 | #ifndef MAXATTEMPTS 43 | #define MAXATTEMPTS 3000 44 | #endif 45 | 46 | class Generator 47 | { 48 | 49 | public: 50 | enum Stage 51 | { 52 | STAGE_MAIN, 53 | STAGE_FORM, 54 | STAGE_HEAD 55 | }; 56 | 57 | typedef std::unordered_map item_map; 58 | typedef std::unordered_map itemSet_map; 59 | 60 | private: 61 | itemSet_map states; 62 | ForestMap forestMap; 63 | item_map itemMap; 64 | nodePtr nodeRoot; 65 | 66 | std::string compactedLexiconFileName; 67 | std::string compactedDirectoryName; 68 | class CompactedLexicon *compactedLexicon; 69 | 70 | unsigned int maxLength; 71 | unsigned int maxUsages; 72 | unsigned int maxItems; 73 | unsigned int maxAttemps; 74 | std::string macrosFileName; 75 | std::string lexiconFileName; 76 | std::string rulesFileName; 77 | std::string inputFileName; 78 | 79 | std::list inputs; 80 | 81 | bool reduceAll; 82 | bool trace; 83 | bool verbose; 84 | bool warning; 85 | bool randomResult; 86 | bool firstResult; 87 | 88 | MemoizationMap memoizedMap; 89 | 90 | bool traceInit; 91 | bool traceStage; 92 | bool traceClose; 93 | bool traceShift; 94 | bool traceReduce; 95 | bool traceAction; 96 | 97 | #ifdef OUTPUT_XML 98 | char *outXML; 99 | #endif 100 | 101 | public: 102 | Generator(); 103 | 104 | ~Generator(); 105 | 106 | itemSet_map::const_iterator cbeginStates() const; 107 | 108 | itemSet_map::const_iterator cendStates() const; 109 | 110 | size_t sizeStates() const; 111 | 112 | bool emptyInputs(void); 113 | 114 | std::list::const_iterator cbeginInputs(void); 115 | 116 | std::list::const_iterator cendInputs(void); 117 | 118 | void addInput (const std::string &input); 119 | 120 | void setInputFileName(char *); 121 | 122 | void setMacrosFileName(char *); 123 | 124 | void setLexiconFileName(char *); 125 | 126 | void setRulesFileName(char *); 127 | 128 | void setCompactedLexiconFileName(char *); 129 | 130 | void setCompactedDirectoryName(char *); 131 | 132 | std::string getInputFileName() const; 133 | 134 | std::string getLexiconFileName() const; 135 | 136 | std::string getMacrosFileName() const; 137 | 138 | std::string getCompactedLexiconFileName() const; 139 | 140 | std::string getCompactedDirectoryName() const; 141 | 142 | std::string getRulesFileName() const; 143 | 144 | void setMaxLength(unsigned int); 145 | 146 | void setMaxUsages(unsigned int); 147 | 148 | unsigned int getMaxUsages() const; 149 | 150 | void setMaxItems(unsigned int); 151 | 152 | void setMaxAttemps(unsigned int); 153 | 154 | unsigned int getMaxItems() const; 155 | 156 | void setCompactedLexicon(class CompactedLexicon *); 157 | 158 | #ifdef OUTPUT_XML 159 | void setOutXML(char *); 160 | char *getOutXML() const; 161 | #endif 162 | 163 | void setTraceInit(bool); 164 | void setTraceStage(bool); 165 | void setTraceClose(bool); 166 | void setTraceShift(bool); 167 | void setTraceReduce(bool); 168 | void setTraceAction(bool); 169 | bool getTraceInit(); 170 | bool getTraceStage(); 171 | bool getTraceClose(); 172 | bool getTraceShift(); 173 | bool getTraceReduce(); 174 | bool getTraceAction(); 175 | 176 | nodePtr getNodeRoot(); 177 | 178 | bool insertItemMap(class Item *); 179 | 180 | void eraseItemMap(uint32_t); 181 | 182 | class Item *getItemMap(uint32_t); 183 | 184 | bool getTrace() const; 185 | 186 | void setTrace(bool); 187 | 188 | void setReduceAll(bool); 189 | 190 | void setRandomResult(bool); 191 | 192 | bool getRandomResult(void) const; 193 | 194 | void setFirstResult(bool); 195 | 196 | bool getFirstResult(void) const; 197 | 198 | void printState(std::ostream &, class ItemSet *); 199 | 200 | void close(class Parser &, class ItemSet *, uint32_t); 201 | 202 | bool shift(class Parser &, class ItemSet *, uint32_t); 203 | 204 | void clear(); 205 | 206 | static class Item *createItem(class Item *, uint32_t); 207 | 208 | void generate(class Parser &); 209 | 210 | entriesPtr findCompactedLexicon(class Parser &parser, uint32_t pos, uint32_t head); 211 | 212 | std::string keyMemoization(class Item *, class Item *); 213 | 214 | void setVerbose(bool); 215 | 216 | bool getVerbose(); 217 | 218 | entriesPtr findByHead(Parser::entries_map *map, uint32_t head); 219 | 220 | entriesPtr findByHeadThenCompactedLexicon(Parser &parser, Parser::entries_map *map, uint32_t pos, uint32_t head); 221 | 222 | entriesPtr findMain(Parser::entries_map *map); 223 | 224 | entriesPtr findByForm(Parser::entries_map *map); 225 | }; 226 | 227 | #endif // ELVEX_GENERATOR_H 228 | -------------------------------------------------------------------------------- /src/bitset.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include 21 | #include 22 | #include "bitset.hpp" 23 | #include "vartable.hpp" 24 | #include "messages.hpp" 25 | #include "shared_ptr.hpp" 26 | 27 | /* ************************************************************ 28 | * * 29 | ************************************************************ */ 30 | Bitset::Bitset(unsigned int data) 31 | : std::bitset(data) 32 | { 33 | NEW; 34 | } 35 | 36 | /* ************************************************************ 37 | * * 38 | ************************************************************ */ 39 | Bitset::Bitset(const std::bitset &data) 40 | : std::bitset(data) 41 | { 42 | NEW; 43 | } 44 | 45 | /* ************************************************************ 46 | * * 47 | ************************************************************ */ 48 | Bitset::Bitset(const bitsetPtr &bitset) 49 | : std::bitset(*bitset) 50 | { 51 | NEW; 52 | } 53 | 54 | /* ************************************************************ 55 | * * 56 | ************************************************************ */ 57 | Bitset::~Bitset() 58 | { 59 | DELETE; 60 | } 61 | 62 | /* ************************************************************ 63 | * * 64 | ************************************************************ */ 65 | bitsetPtr Bitset::create(unsigned int data) 66 | { 67 | return std::make_shared(data); 68 | } 69 | 70 | /* ************************************************************ 71 | * * 72 | ************************************************************ */ 73 | bitsetPtr Bitset::create(std::bitset data) 74 | { 75 | return std::make_shared(data); 76 | } 77 | 78 | /* ************************************************************ 79 | * * 80 | ************************************************************ */ 81 | bitsetPtr Bitset::create(const bitsetPtr &data) 82 | { 83 | return std::make_shared(data); 84 | } 85 | 86 | /* ************************************************************ 87 | * * 88 | ************************************************************ */ 89 | std::string Bitset::toString() const 90 | { 91 | std::stringstream s; 92 | size_t c = this->count(); 93 | size_t sz = this->size(); 94 | for (size_t i = 0; i < sz && c > 0; ++i) 95 | { 96 | if ((*this)[i]) 97 | { 98 | --c; 99 | s << Vartable::bitToName(i); 100 | if (c > 0) 101 | s << '|'; 102 | } 103 | } 104 | return s.str(); 105 | } 106 | 107 | /* ************************************************************ 108 | * * 109 | ************************************************************ */ 110 | std::string replaceZeroSequences(const std::string& input) { 111 | std::string result; 112 | size_t count = 0; 113 | 114 | for (char c : input) { 115 | if (c == '0') { 116 | count++; 117 | } else { 118 | if (count > 0) { 119 | result += "_#" + std::to_string(count) + "_"; 120 | count = 0; 121 | } 122 | result += c; 123 | } 124 | } 125 | 126 | if (count > 0) { 127 | result += "_#" + std::to_string(count) + "_"; 128 | } 129 | 130 | return result; 131 | } 132 | 133 | /* ************************************************************ 134 | * template 135 | * serialString = std::hex numbers from right to left 136 | ************************************************************ */ 137 | void Bitset::makeSerialString(){ 138 | serialString = replaceZeroSequences(this->to_string()); 139 | } 140 | 141 | #ifdef OUTPUT_XML 142 | /* ************************************************************ 143 | * * 144 | ************************************************************ */ 145 | void Bitset::toXML(xmlNodePtr nodeRoot) 146 | { 147 | xmlNodePtr f = xmlNewChild(nodeRoot, nullptr, (const xmlChar *)"ALT", nullptr); 148 | Vartable::uint32_t_to_string_iterator varTableIt; 149 | size_t c = this->count(); 150 | size_t sz = this->size(); 151 | for (unsigned int i = 0; i < sz && c > 0; ++i) 152 | if (this->test(i)) 153 | { 154 | --c; 155 | varTableIt = Vartable::bitMapFind(i); 156 | if (varTableIt != Vartable::bitMapcEnd()) 157 | xmlNewChild(f, nullptr, (const xmlChar *)"OPT", (const xmlChar *)varTableIt->second.c_str()); 158 | } 159 | } 160 | #endif 161 | 162 | /* ************************************************************ 163 | * * 164 | ************************************************************ */ 165 | bitsetPtr Bitset::clone() 166 | { 167 | return create(*this); 168 | } 169 | -------------------------------------------------------------------------------- /src/itemset.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include 21 | #include "itemset.hpp" 22 | #include "messages.hpp" 23 | #include "rule.hpp" 24 | #include "generator.hpp" 25 | 26 | /* ************************************************** 27 | * 28 | ************************************************** */ 29 | ItemSet::ItemSet(unsigned int id) 30 | { 31 | NEW; 32 | this->id = id; 33 | } 34 | 35 | /* ************************************************** 36 | * 37 | ************************************************** */ 38 | ItemSet::~ItemSet() 39 | { 40 | DELETE; 41 | for (auto tmp : items) 42 | { 43 | if (tmp) 44 | free(tmp); 45 | } 46 | items.clear(); 47 | } 48 | 49 | /* ************************************************** 50 | * 51 | ************************************************** */ 52 | class ItemSet *ItemSet::create(unsigned int id) 53 | { 54 | return new ItemSet(id); 55 | } 56 | 57 | /* ************************************************** 58 | * 59 | ************************************************** */ 60 | unsigned int ItemSet::getId(void) 61 | { 62 | return id; 63 | } 64 | 65 | /* ************************************************** 66 | * 67 | ************************************************** */ 68 | ItemSet::set_of_item &ItemSet::getItems() 69 | { 70 | return items; 71 | } 72 | 73 | /* ************************************************** 74 | * 75 | ************************************************** */ 76 | ItemSet::set_of_item_const_iterator ItemSet::cbegin() const 77 | { 78 | return items.cbegin(); 79 | } 80 | 81 | /* ************************************************** 82 | * 83 | ************************************************** */ 84 | ItemSet::set_of_item_const_iterator ItemSet::cend() const 85 | { 86 | return items.cend(); 87 | } 88 | 89 | /* ************************************************** 90 | * 91 | ************************************************** */ 92 | ItemSet::set_of_item_iterator ItemSet::begin() 93 | { 94 | return items.begin(); 95 | } 96 | 97 | /* ************************************************** 98 | * 99 | ************************************************** */ 100 | ItemSet::set_of_item_iterator ItemSet::end() 101 | { 102 | return items.end(); 103 | } 104 | 105 | /* ************************************************** 106 | * 107 | ************************************************** */ 108 | ItemSet::set_of_item_const_iterator ItemSet::find(class Item *item) const 109 | { 110 | return items.find(item); 111 | } 112 | 113 | /* ************************************************** 114 | * 115 | ************************************************** */ 116 | bool ItemSet::insert(class Item *item, Generator *synthesizer) 117 | { 118 | if (items.size() > synthesizer->getMaxItems()) 119 | { 120 | std::ostringstream oss; 121 | oss << "too much items build : " << items.size() << " (" << synthesizer->getMaxItems() << " Max)"; 122 | throw fatal_exception(oss); 123 | } 124 | #ifdef TRACE_INSERT 125 | std::cout << "

####################### INSERT " << item->getId() << " #######################

" << std::endl; 126 | item->print(std::cout); 127 | std::cout << std::endl; 128 | #endif 129 | return items.insert(item).second; 130 | } 131 | 132 | /* ************************************************** 133 | * 134 | ************************************************** */ 135 | void ItemSet::erase(class Item *item) 136 | { 137 | items.erase(item); 138 | } 139 | 140 | /* ************************************************** 141 | * 142 | ************************************************** */ 143 | size_t ItemSet::size() const 144 | { 145 | return items.size(); 146 | } 147 | 148 | /* ************************************************** 149 | * 150 | ************************************************** */ 151 | void ItemSet::resetUsages() 152 | { 153 | for (const auto &item : items) 154 | { 155 | item->ruleResetUsages(); 156 | } 157 | } 158 | 159 | /* ************************************************** 160 | * 161 | ************************************************** */ 162 | void ItemSet::print(std::ostream &oss) 163 | { 164 | oss << ""; 165 | for (const auto &item : items) 166 | { 167 | oss << ""; 168 | oss << ""; 171 | oss << ""; 172 | } 173 | oss << "
"; 169 | item->print(oss); 170 | oss << "
"; 174 | } 175 | 176 | #ifdef OUTPUT_XML 177 | /* ************************************************** 178 | * 179 | ************************************************** */ 180 | void ItemSet::toXML(xmlNodePtr node) 181 | { 182 | xmlNodePtr s = xmlNewChild(node, NULL, (const xmlChar *)"STATE", NULL); 183 | xmlSetProp(s, (xmlChar *)"id", (xmlChar *)(std::to_string(this->id)).c_str()); 184 | xmlSetProp(s, (xmlChar *)"fillcolor", (xmlChar *)"WHITE"); 185 | xmlSetProp(s, (xmlChar *)"color", (xmlChar *)"BLACK"); 186 | std::ostringstream oss; 187 | oss << ""; 188 | oss << ""; 189 | oss << ""; 190 | oss << ""; 193 | oss << ""; 194 | oss << "
Q" << id << "
"; 191 | print(oss); 192 | oss << "
"; 195 | xmlSetProp(s, (xmlChar *)"rule", (xmlChar *)(oss.str().c_str())); 196 | } 197 | #endif 198 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(elvex VERSION 2.27.0) 4 | 5 | set(CMAKE_VERBOSE_MAKEFILE OFF) 6 | set(CMAKE_CXX_COMPILER g++) 7 | set(CMAKE_CXX_STANDARD 11) 8 | include_directories(src) 9 | 10 | find_package(BISON) 11 | if (BISON_FOUND) 12 | BISON_TARGET(rulesyacc src/rulesyacc.y ${CMAKE_CURRENT_BINARY_DIR}/src/rulesyacc.cc 13 | DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/src/rulesyacc.hpp 14 | COMPILE_FLAGS "-p rules") 15 | else() 16 | message("bison not found") 17 | endif() 18 | 19 | find_package(FLEX) 20 | if (FLEX_FOUND) 21 | FLEX_TARGET(ruleslex src/ruleslex.l ${CMAKE_CURRENT_BINARY_DIR}/src/ruleslex.cc 22 | COMPILE_FLAGS "-Prules") 23 | else() 24 | message("flex not found") 25 | endif() 26 | 27 | ADD_FLEX_BISON_DEPENDENCY(ruleslex rulesyacc) 28 | 29 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) 30 | 31 | set(ELVEX_COMMON_SOURCES 32 | ${BISON_rulesyacc_OUTPUTS} 33 | ${FLEX_ruleslex_OUTPUTS} 34 | src/bitset.cc 35 | src/bitset.hpp 36 | src/compacted-lexicon-buffer.cc 37 | src/compacted-lexicon-buffer.hpp 38 | src/compacted-lexicon-fsa.cc 39 | src/compacted-lexicon-fsa.hpp 40 | src/compacted-lexicon-info.cc 41 | src/compacted-lexicon-info.hpp 42 | src/compacted-lexicon-tree.cc 43 | src/compacted-lexicon-tree.hpp 44 | src/compacted-lexicon.cc 45 | src/compacted-lexicon.hpp 46 | src/config.hpp 47 | src/entries.cc 48 | src/entries.hpp 49 | src/entry.cc 50 | src/entry.hpp 51 | src/environment.cc 52 | src/environment.hpp 53 | src/facade.cc 54 | src/facade.hpp 55 | src/fatal_exception.cc 56 | src/fatal_exception.hpp 57 | src/feature.cc 58 | src/feature.hpp 59 | src/features.cc 60 | src/features.hpp 61 | src/flags.cc 62 | src/flags.hpp 63 | src/forest.cc 64 | src/forest.hpp 65 | src/forestidentifier.cc 66 | src/forestidentifier.hpp 67 | src/forestmap.cc 68 | src/forestmap.hpp 69 | src/generator.cc 70 | src/generator.hpp 71 | src/item.cc 72 | src/item.hpp 73 | src/itemset.cc 74 | src/itemset.hpp 75 | src/lexicon.cc 76 | src/lexicon.hpp 77 | src/listfeatures.cc 78 | src/listfeatures.hpp 79 | src/memoization-map.cc 80 | src/memoization-map.hpp 81 | src/memoization-value.cc 82 | src/memoization-value.hpp 83 | src/messages.hpp 84 | src/node.cc 85 | src/node.hpp 86 | src/pairp.cc 87 | src/pairp.hpp 88 | src/parser.cc 89 | src/parser.hpp 90 | src/parser_exception.cc 91 | src/parser_exception.hpp 92 | src/rule.cc 93 | src/rule.hpp 94 | src/rules.cc 95 | src/rules.hpp 96 | src/serializable.cc 97 | src/serializable.hpp 98 | src/shared_ptr.hpp 99 | src/statement.cc 100 | src/statement.hpp 101 | src/statements.cc 102 | src/statements.hpp 103 | src/terms.cc 104 | src/terms.hpp 105 | src/uniq-id.cc 106 | src/uniq-id.hpp 107 | src/usage_exception.cc 108 | src/usage_exception.hpp 109 | src/value.cc 110 | src/value.hpp 111 | src/variableflag.cc 112 | src/variableflag.hpp 113 | src/vartable.cc 114 | src/vartable.hpp) 115 | 116 | configure_file( 117 | src/config.hpp.in 118 | src/config.hpp 119 | @ONLY) 120 | 121 | add_executable(elvex ${ELVEX_COMMON_SOURCES} src/elvex.cc src/fatal_exception.cc src/fatal_exception.hpp) 122 | target_compile_options(elvex PUBLIC -O4 -Wall -Wextra -Wno-deprecated -Wno-sign-compare -Wno-missing-field-initializers 123 | #target_compile_options(elvex PUBLIC -g -Wall -Wextra -Wno-deprecated -Wno-sign-compare -Wno-missing-field-initializers 124 | #-DDEBUGYACC\(x\)=x 125 | #-DDEBUGLEX\(x\)=x 126 | ) 127 | 128 | find_package(LibXml2 REQUIRED) 129 | if (LibXml2_FOUND) 130 | target_compile_definitions(elvex PUBLIC 131 | MAXFLAGS=16 132 | OUTPUT_XML 133 | MAXBITS=512 134 | MAXLENGTH=12000 135 | MAXUSAGES=12000 136 | MAXITEMS=12000 137 | MAXATTEMPTS=1200 138 | #TRACE_ENVIRONMENT 139 | #TRACE_BUILD_ENVIRONMENT 140 | #TRACE_ENABLE_STATEMENT 141 | #TRACE_APPLY_STATEMENT 142 | #TRACE_FEATURES 143 | #TRACE_STEP 144 | #TRACE_PASS 145 | #TRACE_UNFOLD 146 | #TRACE_MEMOIZATION 147 | #TRACE_LEXICON 148 | ) 149 | target_link_libraries(elvex PUBLIC ${LIBXML2_LIBRARIES}) 150 | target_include_directories(elvex PUBLIC ${LIBXML2_INCLUDE_DIR}) 151 | else() 152 | message("libxml2 not found") 153 | endif() 154 | 155 | add_executable(elvexlexicon ${ELVEX_COMMON_SOURCES} src/buildlexicon.cc) 156 | target_compile_options(elvexlexicon PUBLIC -O4 -Wall -Wextra -Wno-deprecated -Wno-sign-compare -Wno-missing-field-initializers) 157 | target_compile_definitions(elvexlexicon PUBLIC 158 | #TRACE_DIFF 159 | ) 160 | 161 | FLEX_TARGET(postedition_en src/postedition_en.l ${CMAKE_CURRENT_BINARY_DIR}/src/postedition_en.cc) 162 | add_executable(elvexpostedition_en ${FLEX_postedition_en_OUTPUTS}) 163 | target_compile_options(elvexpostedition_en PUBLIC -O4 -Wall -Wextra -Wno-deprecated -Wno-sign-compare -Wno-missing-field-initializers) 164 | 165 | FLEX_TARGET(postedition_fr src/postedition_fr.l ${CMAKE_CURRENT_BINARY_DIR}/src/postedition_fr.cc) 166 | add_executable(elvexpostedition_fr ${FLEX_postedition_fr_OUTPUTS}) 167 | target_compile_options(elvexpostedition_fr PUBLIC -O4 -Wall -Wextra -Wno-deprecated -Wno-sign-compare -Wno-missing-field-initializers) 168 | 169 | install(TARGETS elvex elvexlexicon elvexpostedition_en elvexpostedition_fr 170 | RUNTIME DESTINATION bin) 171 | 172 | -------------------------------------------------------------------------------- /src/terms.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include "terms.hpp" 21 | #include "messages.hpp" 22 | #include "shared_ptr.hpp" 23 | #include "vartable.hpp" 24 | 25 | /* ************************************************** 26 | * 27 | ************************************************** */ 28 | Terms::Terms(std::vector &terms, bool optional) 29 | { 30 | this->terms = terms; 31 | this->optional = optional; 32 | NEW; 33 | } 34 | 35 | /* ************************************************** 36 | * 37 | ************************************************** */ 38 | Terms::Terms(uint32_t term, bool optional) 39 | { 40 | this->terms.push_back(term); 41 | this->optional = optional; 42 | NEW; 43 | } 44 | 45 | /* ************************************************** 46 | * 47 | ************************************************** */ 48 | Terms::Terms() 49 | { 50 | this->optional = false; 51 | NEW; 52 | } 53 | 54 | /* ************************************************** 55 | * 56 | ************************************************** */ 57 | Terms::~Terms() 58 | { 59 | DELETE; 60 | } 61 | 62 | /* ************************************************** 63 | * 64 | ************************************************** */ 65 | termsPtr Terms::create(std::vector &terms, bool optional) 66 | { 67 | return termsPtr(new Terms(terms, optional)); 68 | } 69 | 70 | /* ************************************************** 71 | * 72 | ************************************************** */ 73 | termsPtr Terms::create(uint32_t term, bool optional) 74 | { 75 | return termsPtr(new Terms(term, optional)); 76 | } 77 | 78 | /* ************************************************** 79 | * 80 | ************************************************** */ 81 | termsPtr Terms::create() 82 | { 83 | return termsPtr(new Terms()); 84 | } 85 | 86 | /* ************************************************** 87 | * 88 | ************************************************** */ 89 | bool Terms::isOptional(void) const 90 | { 91 | return optional; 92 | } 93 | 94 | /* ************************************************** 95 | * 96 | ************************************************** */ 97 | void Terms::setOptional() 98 | { 99 | this->optional = true; 100 | } 101 | 102 | /* ************************************************** 103 | * 104 | ************************************************** */ 105 | void Terms::unsetOptional() 106 | { 107 | this->optional = false; 108 | } 109 | 110 | /* ************************************************** 111 | * 112 | ************************************************** */ 113 | size_t Terms::size(void) const 114 | { 115 | return terms.size(); 116 | } 117 | 118 | /* ************************************************** 119 | * 120 | ************************************************** */ 121 | std::vector::const_iterator Terms::begin(void) const 122 | { 123 | return terms.begin(); 124 | } 125 | 126 | /* ************************************************** 127 | * 128 | ************************************************** */ 129 | std::vector::const_iterator Terms::end(void) const 130 | { 131 | return terms.end(); 132 | } 133 | 134 | /* ************************************************** 135 | * 136 | ************************************************** */ 137 | void Terms::erase(std::vector::iterator begin, std::vector::iterator end) 138 | { 139 | terms.erase(begin, end); 140 | } 141 | 142 | /* ************************************************** 143 | * 144 | ************************************************** */ 145 | void Terms::push_back(uint32_t term) 146 | { 147 | terms.push_back(term); 148 | } 149 | 150 | /* ************************************************** 151 | * 152 | ************************************************** */ 153 | bool Terms::Less::operator()(const termsPtr t1, const termsPtr t2) const 154 | { 155 | if (t1->optional != t2->optional) 156 | return (t1->optional < t2->optional); 157 | 158 | if (t1->size() != t2->size()) 159 | return (t1->size() < t2->size()); 160 | 161 | auto s1 = t1->begin(); 162 | auto s2 = t2->begin(); 163 | while (s1 != t1->end()) 164 | { 165 | if ((*s1) != (*s2)) 166 | return ((*s1) < (*s2)); 167 | ++s1; 168 | ++s2; 169 | } 170 | return false; 171 | } 172 | 173 | /* ************************************************** 174 | * 175 | ************************************************** */ 176 | void Terms::print(std::ostream &outStream) 177 | { 178 | if (optional) 179 | outStream << '['; 180 | if (size() > 1) 181 | { 182 | bool first = true; 183 | for (auto term = this->begin(); term != this->end(); ++term) 184 | { 185 | if (first) 186 | first = false; 187 | else 188 | outStream << '|'; 189 | outStream << Vartable::codeToName(*term); 190 | } 191 | } 192 | else 193 | { 194 | outStream << Vartable::codeToName(terms[0]); 195 | } 196 | if (optional) 197 | outStream << ']'; 198 | } 199 | 200 | /* ************************************************** 201 | * 202 | ************************************************** */ 203 | termsPtr Terms::clone(void) const 204 | { 205 | std::vector new_terms; 206 | for (auto t = begin(); t != end(); ++t) 207 | new_terms.push_back((*t)); 208 | return Terms::create(new_terms, optional); 209 | } 210 | 211 | /* ************************************************** 212 | * 213 | ************************************************** */ 214 | uint32_t Terms::operator[](size_t i) 215 | { 216 | return terms[i]; 217 | } 218 | -------------------------------------------------------------------------------- /src/listfeatures.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include 21 | #include "listfeatures.hpp" 22 | #include "features.hpp" 23 | #include "shared_ptr.hpp" 24 | #include "messages.hpp" 25 | #include "statement.hpp" 26 | 27 | /* ************************************************** 28 | * 29 | ************************************************** */ 30 | ListFeatures::ListFeatures() 31 | { 32 | NEW; 33 | } 34 | 35 | /* ************************************************** 36 | * 37 | ************************************************** */ 38 | ListFeatures::~ListFeatures() 39 | { 40 | DELETE; 41 | for (auto &listFeature : listFeatures) 42 | listFeature.reset(); 43 | } 44 | 45 | /* ************************************************** 46 | * 47 | ************************************************** */ 48 | listFeaturesPtr ListFeatures::create() 49 | { 50 | return std::make_shared(); 51 | } 52 | 53 | /* ************************************************** 54 | * 55 | ************************************************** */ 56 | featuresPtr ListFeatures::operator[](unsigned int j) 57 | { 58 | return listFeatures[j]; 59 | } 60 | 61 | /* ************************************************** 62 | * 63 | ************************************************** */ 64 | void ListFeatures::push_back(const featuresPtr &fs) 65 | { 66 | listFeatures.push_back(fs); 67 | } 68 | 69 | /* ************************************************** 70 | * 71 | ************************************************** */ 72 | void ListFeatures::add(unsigned int j, featuresPtr fs) 73 | { 74 | listFeatures[j] = std::move(fs); 75 | } 76 | 77 | /* ************************************************** 78 | * 79 | ************************************************** */ 80 | featuresPtr ListFeatures::get(unsigned int j) 81 | { 82 | return listFeatures[j]; 83 | } 84 | 85 | /* ************************************************** 86 | * 87 | ************************************************** */ 88 | void ListFeatures::clear() 89 | { 90 | listFeatures.clear(); 91 | } 92 | 93 | /* ************************************************** 94 | * 95 | ************************************************** */ 96 | std::vector::const_iterator ListFeatures::cbegin() const 97 | { 98 | return listFeatures.cbegin(); 99 | } 100 | 101 | /* ************************************************** 102 | * 103 | ************************************************** */ 104 | std::vector::const_iterator ListFeatures::cend() const 105 | { 106 | return listFeatures.cend(); 107 | } 108 | 109 | /* ************************************************** 110 | * 111 | ************************************************** */ 112 | std::vector::iterator ListFeatures::begin() 113 | { 114 | return listFeatures.begin(); 115 | } 116 | 117 | /* ************************************************** 118 | * 119 | ************************************************** */ 120 | std::vector::iterator ListFeatures::end() 121 | { 122 | return listFeatures.end(); 123 | } 124 | 125 | /* ************************************************** 126 | * 127 | ************************************************** */ 128 | size_t ListFeatures::size() const 129 | { 130 | return listFeatures.size(); 131 | } 132 | 133 | /* ************************************************** 134 | * 135 | ************************************************** */ 136 | listFeaturesPtr ListFeatures::clone() 137 | { 138 | listFeaturesPtr lf = ListFeatures::create(); 139 | for (auto &listFeature : listFeatures) 140 | lf->push_back(listFeature->clone()); 141 | return lf; 142 | } 143 | 144 | /* ************************************************** 145 | * 146 | ************************************************** */ 147 | void ListFeatures::print(std::ostream &outStream) const 148 | { 149 | outStream << R"()"; 150 | outStream << R"()"; 151 | for (auto &listFeature : listFeatures) 152 | listFeature->print(outStream); 153 | outStream << ""; 154 | outStream << "
"; 155 | } 156 | 157 | /* ************************************************** 158 | * 159 | ************************************************** */ 160 | void ListFeatures::flatPrint(std::ostream &outStream) const 161 | { 162 | outStream << '('; 163 | bool first = true; 164 | for (auto &listFeature : listFeatures) 165 | { 166 | if (first) 167 | first = false; 168 | else 169 | outStream << ", "; 170 | listFeature->flatPrint(outStream); 171 | } 172 | outStream << ')'; 173 | } 174 | 175 | /* ************************************************************ 176 | * * 177 | ************************************************************ */ 178 | void ListFeatures::apply(statementPtr statementRoot, class Item *item, Parser &parser, Generator *synthesizer, const statementPtr &variable, statementPtr statement, 179 | bool &effect, bool verbose) 180 | { 181 | for (auto &features : listFeatures) 182 | { 183 | features->apply(statementRoot, item, parser, synthesizer, variable, statement->clone(0), effect, verbose); 184 | } 185 | } 186 | 187 | /* ************************************************** 188 | * 189 | ************************************************** */ 190 | void ListFeatures::makeSerialString() 191 | { 192 | std::ostringstream stream; 193 | stream << '-'; 194 | for (auto &features : listFeatures) 195 | { 196 | stream << features->peekSerialString() << '-'; 197 | } 198 | serialString = stream.str(); 199 | } 200 | 201 | #ifdef OUTPUT_XML 202 | /* ************************************************** 203 | * 204 | ************************************************** */ 205 | void ListFeatures::toXML(xmlNodePtr nodeRoot) 206 | { 207 | xmlNodePtr lfs = xmlNewChild(nodeRoot, nullptr, (const xmlChar *)"LFS", nullptr); 208 | xmlSetProp(lfs, (xmlChar *)"id", (xmlChar *)this->getIdStr().c_str()); 209 | for (auto &features : listFeatures) 210 | { 211 | features->toXML(lfs); 212 | } 213 | } 214 | #endif 215 | -------------------------------------------------------------------------------- /xsl/xml2CS-dot-graph.xsl: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 24 | 25 | 26 | 27 | 100% 28 | 0 29 | 0.75 30 | 0 31 | 32 | 33 | 34 | digraph G{ graph[center="yes",size=" 35 | 36 | " 37 | ]; node[fontnames="Palatino-Roman",fontsize="12",fontcolor="black",style="filled",fillcolor="white",width="0",height="0",shape="ellipse",penwidth="1"]; edge[arrowtail="none",arrowhead="normal"]; 38 | 39 | 40 | 41 | 42 | } 43 | 44 | 45 | 47 | 48 | 49 | _ 50 | [shape="box",color=red,style="filled",height="0.1",width="0.1",fontcolor="black" 51 | ,label=" 52 | 53 | "]; 54 | 55 | 56 | 57 | 58 | 59 | _ 60 | [shape="none",height="0.15",width="0.15",fontcolor="black" 61 | ,label=" 62 | 63 | "]; 64 | 65 | _ 66 | -> 67 | _ 68 | ; 69 | 70 | 71 | _ 72 | -> 73 | _ 74 | [label=" 75 | 76 | "]; 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | _ 85 | -> 86 | _ 87 | [label=" 88 | 89 | "]; 90 | 91 | 92 | 93 | 94 | 95 | 97 | 98 | 99 | 100 | _ 101 | [shape="none",label=" 102 | 103 | " 104 | 105 | 106 | 107 | ,fillcolor="red" 108 | 109 | 110 | ,fillcolor="violet",fontcolor="white" 111 | 112 | 113 | 114 | ]; 115 | 116 | 117 | 118 | 119 | 121 | 122 | 123 | _ 124 | [shape="box",label=" 125 | "]; 126 | 127 | 128 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | \n 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /src/forest.cc: -------------------------------------------------------------------------------- 1 | /* ************************************************** 2 | * 3 | * ELVEX 4 | * 5 | * Copyright 2014-2023 LABRI, 6 | * CNRS (UMR 5800), the University of Bordeaux, 7 | * and the Bordeaux INP 8 | * 9 | * Author: 10 | * Lionel Clément 11 | * LaBRI - Université Bordeaux 12 | * 351, cours de la Libération 13 | * 33405 Talence Cedex - France 14 | * lionel.clement@u-bordeaux.fr 15 | * 16 | * This file is part of ELVEX. 17 | * 18 | ************************************************** */ 19 | 20 | #include 21 | #include 22 | 23 | #include "forest.hpp" 24 | #include "messages.hpp" 25 | #include "shared_ptr.hpp" 26 | #include "node.hpp" 27 | 28 | std::string Forest::EMPTY_FORM = ""; 29 | 30 | /* ************************************************** 31 | * 32 | ************************************************** */ 33 | Forest::Forest(uint32_t from, uint32_t to, std::string &form) 34 | { 35 | NEW; 36 | this->from = from; 37 | this->to = to; 38 | if (from == to) 39 | this->empty = true; 40 | else 41 | this->empty = false; 42 | this->form = form; 43 | } 44 | 45 | /* ************************************************** 46 | * 47 | ************************************************** */ 48 | forestPtr Forest::create(uint32_t from, uint32_t to, std::string &form) 49 | { 50 | return std::make_shared(from, to, form); 51 | } 52 | 53 | /* ************************************************** 54 | * 55 | ************************************************** */ 56 | Forest::~Forest() 57 | { 58 | DELETE; 59 | for (auto tmp : nodes) 60 | { 61 | if (tmp) 62 | tmp.reset(); 63 | } 64 | } 65 | 66 | /* ************************************************** 67 | * 68 | ************************************************** */ 69 | uint32_t Forest::getFrom() const 70 | { 71 | return from; 72 | } 73 | 74 | /* ************************************************** 75 | * 76 | ************************************************** */ 77 | uint32_t Forest::getTo() const 78 | { 79 | return to; 80 | } 81 | 82 | /* ************************************************** 83 | * 84 | ************************************************** */ 85 | bool Forest::output_empty() const 86 | { 87 | return output.empty(); 88 | } 89 | 90 | /* ************************************************** 91 | * 92 | ************************************************** */ 93 | const std::forward_list::const_iterator Forest::output_cbegin() const 94 | { 95 | return output.cbegin(); 96 | } 97 | 98 | /* ************************************************** 99 | * 100 | ************************************************** */ 101 | const std::forward_list::const_iterator Forest::output_cend() const 102 | { 103 | return output.cend(); 104 | } 105 | 106 | /* ************************************************** 107 | * 108 | ************************************************** */ 109 | void Forest::push_output(std::string str) 110 | { 111 | output.push_front(str); 112 | } 113 | 114 | /* ************************************************** 115 | * 116 | ************************************************** */ 117 | void Forest::push_node(const nodePtr &node) 118 | { 119 | empty = false; 120 | nodes.push_back(node); 121 | } 122 | 123 | /* ************************************************** 124 | * 125 | ************************************************** */ 126 | std::string &Forest::getForm(void) 127 | { 128 | return form; 129 | } 130 | 131 | #ifdef OUTPUT_XML 132 | /* ************************************************** 133 | * 134 | ************************************************** */ 135 | void Forest::toXML(xmlNodePtr nodeRoot, bool root) 136 | { 137 | xmlNodePtr f = xmlNewChild(nodeRoot, NULL, (const xmlChar *)"FOREST", NULL); 138 | if (root) 139 | xmlSetProp(f, (xmlChar *)"root", (xmlChar *)"yes"); 140 | if (isSetFlags(Flags::XML)) 141 | { 142 | xmlSetProp(f, (xmlChar *)"idref", (xmlChar *)(this->getIdStr()).c_str()); 143 | } 144 | else 145 | { 146 | xmlSetProp(f, (xmlChar *)"id", (xmlChar *)(this->getIdStr()).c_str()); 147 | addFlags(Flags::XML); 148 | xmlSetProp(f, (xmlChar *)"from", (xmlChar *)std::to_string(this->from).c_str()); 149 | xmlSetProp(f, (xmlChar *)"to", (xmlChar *)std::to_string(this->to).c_str()); 150 | xmlSetProp(f, (xmlChar *)"size", (xmlChar *)(std::to_string(nodes.size())).c_str()); 151 | 152 | if (empty) 153 | xmlSetProp(f, (xmlChar *)"empty", (xmlChar *)"yes"); 154 | else 155 | xmlSetProp(f, (xmlChar *)"empty", (xmlChar *)"no"); 156 | 157 | // if (terminal) 158 | // terminal->toXML(f); 159 | // if (entry) 160 | // entry->toXML(f); 161 | 162 | if (!output.empty()) 163 | { 164 | xmlNodePtr o = xmlNewChild(f, NULL, (const xmlChar *)"OUTPUT", NULL); 165 | for (const auto &s : output) 166 | xmlNewChild(o, NULL, (const xmlChar *)"TEXT", (xmlChar *)(s.c_str())); 167 | } 168 | else 169 | { 170 | xmlNodePtr o = xmlNewChild(f, NULL, (const xmlChar *)"OUTPUT", NULL); 171 | xmlNewChild(o, NULL, (const xmlChar *)"TEXT", (xmlChar *)"NONE"); 172 | } 173 | for (Forest::vectorNodes::const_iterator n = nodes.begin(); n != nodes.end(); ++n) 174 | { 175 | (*n)->toXML(nodeRoot, f); 176 | } 177 | } 178 | } 179 | #endif 180 | 181 | /* ************************************************** 182 | * 183 | ************************************************** */ 184 | void Forest::generate(bool randomResult, bool singleResult) 185 | { 186 | if (isUnsetFlags(Flags::GENERATED)) 187 | { 188 | addFlags(Flags::GENERATED); 189 | if (!form.empty()) 190 | { 191 | output.push_front(form); 192 | } 193 | else if (!nodes.empty()) 194 | { 195 | auto nodeIt = nodes.begin(); 196 | nodePtr node; 197 | if (randomResult) 198 | { 199 | size_t rv = std::rand() / ((RAND_MAX + 1u) / nodes.size()); 200 | node = nodes.at(rv); 201 | } 202 | while (nodeIt != nodes.end()) 203 | { 204 | if (!randomResult) 205 | node = *nodeIt; 206 | if (node->isUnsetFlags(Flags::GENERATED)) 207 | { 208 | node->generate(randomResult, singleResult); 209 | } 210 | for (std::forward_list::const_iterator s = node->output_cbegin(); s != node->output_cend(); ++s) 211 | { 212 | output.push_front(*s); 213 | } 214 | if (randomResult || singleResult) 215 | break; 216 | ++nodeIt; 217 | } 218 | } 219 | } 220 | } 221 | --------------------------------------------------------------------------------