diff --git a/.gitignore b/.gitignore index 4f38e59..82d1b3a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ # Lock files from libreoffice .~lock* + +# Jupyter Notebooks +.ipynb_checkpoints/ diff --git a/CategoriesGramaticalesCombinatoire.ods b/CategoriesGramaticalesCombinatoire.ods index 378d3e1..1a1f10a 100644 Binary files a/CategoriesGramaticalesCombinatoire.ods and b/CategoriesGramaticalesCombinatoire.ods differ diff --git a/test.ipynb b/test.ipynb index 74dda21..d16d677 100644 --- a/test.ipynb +++ b/test.ipynb @@ -8,7 +8,7 @@ "source": [ "from nltk.ccg import chart, lexicon\n", "from nltk.ccg.lexicon import CCGLexicon, Token, augParseCategory\n", - "from nltk.ccg.chart import CCGChart,CCGLeafEdge\n", + "from nltk.ccg.chart import CCGChart,CCGLeafEdge,BinaryCombinatorRule,CCGEdge\n", "from nltk.tree import Tree\n", "import pandas as pd\n", "import numpy as np" @@ -56,6 +56,14 @@ "# CYK" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We define the weight associated to each reduction rule.\n", + "`rweight(rule)` should return the weight associated to the rul, using its string representation (i.e. the name of the rule)" + ] + }, { "cell_type": "code", "execution_count": 3, @@ -71,8 +79,24 @@ " if s in valz:\n", " return valz[s]\n", " else:\n", - " return 1.0 # Base rules weight\n", - "\n", + " return 1.0 # Base rules weight" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`weightedParse` implements the CKY algorithm, based on the implementation in the nltk library.\n", + "We take the weight from the weighted lexicon for the leafs, and we compute it using the formula for each reduction rule.\n", + "$$ w_{node} = \\phi_r \\times w_{child1} \\times w_{child2}$$" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ "# Implements the CYK algorithm, code partly taken from nltk\n", "def weightedParse(tokens, lex, rules):\n", " \"\"\"made to take weighed tokens and lexicons\"\"\"\n", @@ -89,7 +113,12 @@ " for span in range(2, chart.num_leaves() + 1):\n", " for start in range(0, chart.num_leaves() - span + 1):\n", " \n", + " print(\"==>\",span,start)\n", + " \n", " bestedge = None\n", + " nedg = 0\n", + " # edges[s] is the best edge generating the category s\n", + " edges = dict()\n", " \n", " # Try all possible pairs of edges that could generate\n", " # an edge for that span\n", @@ -97,40 +126,60 @@ " lstart = start\n", " mid = start + part\n", " rend = start + span\n", - "\n", + " \n", " for left in chart.select(span=(lstart, mid)):\n", " for right in chart.select(span=(mid, rend)):\n", " # Generate all possible combinations of the two edges\n", " for rule in rules:\n", - " edgez = list(rule.apply(chart, lex, left, right))\n", - " if(len(edgez)==1):\n", - " edge = edgez[0]\n", - " edge.weight = rweight(rule) * left.weight * right.weight\n", - " edge.triple = (rule,left,right)\n", - " if (bestedge == None) or (bestedge.weight < edge.weight):\n", - " bestedge = edge\n", - " elif(len(edgez)!=0):\n", - " print(\"Too many new edges (unsupported rule used)\")\n", - " \n", + " # Can we apply the rule\n", + " if rule.can_combine(left.categ(), right.categ()):\n", + " for res in rule.combine(left.categ(), right.categ()):\n", + " # res is the new category\n", + " edge = CCGEdge(\n", + " span=(left.start(), right.end()),\n", + " categ=res,\n", + " rule=BinaryCombinatorRule(rule),\n", + " )\n", + " edge.weight = rweight(rule) * left.weight * right.weight\n", + " edge.triple = (rule,left,right)\n", + " if not(res in edges and edges[res].weight<=edge.weight):\n", + " edges[res] = edge\n", " # end for rule loop\n", " # end for right loop\n", " # end for left loop\n", " # end for part loop\n", - " return chart\n", - "\n", + " for cat in edges:\n", + " chart.insert(edges[cat], (edges[cat].triple[1], edges[cat].triple[2]))\n", + " return chart" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ "def wpToTree(edge):\n", " if isinstance(edge,CCGLeafEdge):\n", " return Tree((edge.token(),\"Leaf\"),[Tree(edge.token(),[edge.leaf()])])\n", " else:\n", " return Tree(\n", " (chart.Token(None,edge.categ()),edge.triple[0].__str__()),\n", - " [wpToTree(t) for t in (edge.triple[1:])])\n", - "\n", + " [wpToTree(t) for t in (edge.triple[1:])])" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ "def bestTree(tokens, lex, rules):\n", " # We build the weighgted parse tree using cky\n", " wChart = weightedParse(tokens, lex, rules)\n", " # We get the biggest edge\n", " e = list(wChart.select(start=0,end=len(tokens)))[0]\n", + " print(\"Edge count:\",len(list(wChart.select(start=0,end=len(tokens)))))\n", " # We get the tree that brought us to this edge\n", " t = wChart._trees(e, True, dict(), Tree)[0]\n", " # (wpToTree(e),e.weight)\n", @@ -146,7 +195,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -154,7 +203,7 @@ "from nltk.sem.logic import Expression\n", "from nltk.ccg.api import PrimitiveCategory\n", "\n", - "def to_pseudo_entries(table, consider_semantics = False):\n", + "def to_pseudo_entries(table, consider_semantics = True):\n", " \"\"\"returns a list of lists in the format ['word', 'category', 'weight', None]\n", " if consider_semantics == false else ['word', 'category', weight, 'semantic']\n", " that is left to be converted into tokens by to_wlex_entries\"\"\"\n", @@ -182,7 +231,7 @@ " categ, _ = augParseCategory(entry[1], primitives, families, var)\n", " token = WeighedToken(token= entry[0],\n", " categ= categ,\n", - " semantics= Expression.fromstring(entry[-1]),\n", + " semantics= None if entry[-1] is None else Expression.fromstring(entry[-1]),\n", " weight= entry[2])\n", " entries[entry[0]].append(token)\n", " return entries\n", @@ -190,507 +239,20 @@ ] }, { - "cell_type": "code", - "execution_count": 9, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{}\n", - "\\n v.à(v,n)\n", - "\\n v.avec(v,n)\n", - "chat\n", - "\\n m.de(n,m)\n", - "dents\n", - "\\n.donne(n)\n", - "\\n m.donne(n,m)\n", - "\\n.mange(n)\n", - "\\n m.mange(n,m)\n", - "donner\n", - "\\n.donner(n)\n", - "\\n.dormir(n)\n", - "\\n.dormir(n)\n", - "elle\n", - "il\n", - "{}\n", - "{}\n", - "{}\n", - "\\n m.et(n,m)\n", - "\\x y.et(x,y)\n", - "\\v w n.et(v,w,n)\n", - "fromage\n", - "{}\n", - "{}\n", - "{}\n", - "\\P.exists x.P(x)\n", - "\\P.exists x.P(x)\n", - "\\P.exists x.P(x)\n", - "\\P.exists x.P(x)\n", - "\\P.exists x.P(x)\n", - "\\n.mangé(n)\n", - "\\n.mangé(n)\n", - "\\n.donné(n)\n", - "\\n.méchant(n)\n", - "\\n.méchant(n)\n", - "\\n.noir(n)\n", - "\\n.noir(n)\n", - "\\v n.paisiblement(v,n)\n", - "{}\n", - "{}\n", - "{}\n", - "{}\n", - "{}\n", - "{}\n", - "{}\n", - "{}\n", - "{}\n", - "{}\n", - "rat\n", - "soeur\n", - "\\n m.souhaite(m,n)\n", - "\\n m.pourchasse(m,n)\n", - "\\n m.attrappe(m,n)\n", - "souris\n", - "{}\n", - "voisin\n", - "1 le chat dort\n", - "Found derivation tree with weight 0.5599999999999999\n", - " le chat dort\n", - " (N/N) {\\P.exists x.P(x)} N {chat} (S\\N) {\\n.dormir(n)}\n", - "------------------------------------>\n", - " N {exists x.chat(x)}\n", - "----------------------------------------------------------<\n", - " S {dormir(exists x.chat(x))}\n", - "1 il dort\n", - "Found derivation tree with weight 0.7\n", - " il dort\n", - " N {il} (S\\N) {\\n.dormir(n)}\n", - "------------------------------<\n", - " S {dormir(il)}\n", - "1 le chat dort paisiblement\n", - "Found derivation tree with weight 0.39199999999999996\n", - " le chat dort paisiblement\n", - " (N/N) {\\P.exists x.P(x)} N {chat} (S\\N) {\\n.dormir(n)} ((S\\N)\\(S\\N)) {\\v n.paisiblement(v,n)}\n", - "------------------------------------>\n", - " N {exists x.chat(x)}\n", - " --------------------------------------------------------------<\n", - " (S\\N) {\\n.paisiblement(\\n.dormir(n),n)}\n", - "--------------------------------------------------------------------------------------------------<\n", - " S {paisiblement(\\n.dormir(n),exists x.chat(x))}\n", - "2 le chat noir dort\n", - "Found derivation tree with weight 0.39199999999999996\n", - " le chat noir dort\n", - " (N/N) {\\P.exists x.P(x)} N {chat} (N\\N) {\\n.noir(n)} (S\\N) {\\n.dormir(n)}\n", - " ------------------------------<\n", - " N {noir(chat)}\n", - "-------------------------------------------------------->\n", - " N {exists x.noir(chat,x)}\n", - "------------------------------------------------------------------------------<\n", - " S {dormir(exists x.noir(chat,x))}\n", - "1 le méchant chat dort\n", - "Found derivation tree with weight 0.44800000000000006\n", - " le méchant chat dort\n", - " (N/N) {\\P.exists x.P(x)} (N/N) {\\n.méchant(n)} N {chat} (S\\N) {\\n.dormir(n)}\n", - " --------------------------------->\n", - " N {méchant(chat)}\n", - "----------------------------------------------------------->\n", - " N {exists x.méchant(chat,x)}\n", - "---------------------------------------------------------------------------------<\n", - " S {dormir(exists x.méchant(chat,x))}\n", - "2 le très méchant chat dort\n", - "Found derivation tree with weight 0.35840000000000005\n", - " le très méchant chat dort\n", - " (N/N) {\\P.exists x.P(x)} ((N/N)/(N/N)) {{}} (N/N) {\\n.méchant(n)} N {chat} (S\\N) {\\n.dormir(n)}\n", - " ------------------------------------------->\n", - " (N/N) {{}(\\n.méchant(n))}\n", - " ----------------------------------------------------->\n", - " N {{}(\\n.méchant(n),chat)}\n", - "------------------------------------------------------------------------------->\n", - " N {exists x.{}(\\n.méchant(n),chat,x)}\n", - "-----------------------------------------------------------------------------------------------------<\n", - " S {dormir(exists x.{}(\\n.méchant(n),chat,x))}\n", - "7 le chat de la sœur de mon voisin dort\n", - "Found derivation tree with weight 0.11239423999999998\n", - " le chat de la sœur de mon voisin dort\n", - " (N/N) {\\P.exists x.P(x)} N {chat} ((N/N)\\N) {\\n m.de(n,m)} (N/N) {\\P.exists x.P(x)} N {soeur} ((N/N)\\N) {\\n m.de(n,m)} (N/N) {\\P.exists x.P(x)} N {voisin} (S\\N) {\\n.dormir(n)}\n", - " ------------------------------------<\n", - " (N/N) {\\m.de(chat,m)}\n", - " -------------------------------------<\n", - " (N/N) {\\m.de(soeur,m)}\n", - " -------------------------------------->\n", - " N {exists x.voisin(x)}\n", - " --------------------------------------------------------------------------->\n", - " N {de(soeur,exists x.voisin(x))}\n", - " ----------------------------------------------------------------------------------------------------->\n", - " N {exists x.de(soeur,exists x.voisin(x),x)}\n", - " ----------------------------------------------------------------------------------------------------------------------------------------->\n", - " N {de(chat,exists x.de(soeur,exists x.voisin(x),x))}\n", - "------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n", - " N {exists x.de(chat,exists x.de(soeur,exists x.voisin(x),x),x)}\n", - "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<\n", - " S {dormir(exists x.de(chat,exists x.de(soeur,exists x.voisin(x),x),x))}\n", - "2 le chat que mon voisin lui donne mange\n", - "Found derivation tree with weight 0.14049279999999997\n", - " le chat que mon voisin lui donne mange\n", - " (N/N) {\\P.exists x.P(x)} N {chat} ((N\\N)/S) {{}} (N/N) {\\P.exists x.P(x)} N {voisin} ((S\\N)/(S\\N)) {{}} (S\\N) {\\n.donne(n)} (S\\N) {\\n.mange(n)}\n", - " -------------------------------------->\n", - " N {exists x.voisin(x)}\n", - " ----------------------------------------->\n", - " (S\\N) {{}(\\n.donne(n))}\n", - " -------------------------------------------------------------------------------<\n", - " S {{}(\\n.donne(n),exists x.voisin(x))}\n", - " ----------------------------------------------------------------------------------------------->\n", - " (N\\N) {{}({}(\\n.donne(n),exists x.voisin(x)))}\n", - " ---------------------------------------------------------------------------------------------------------<\n", - " N {{}({}(\\n.donne(n),exists x.voisin(x)),chat)}\n", - "----------------------------------------------------------------------------------------------------------------------------------->\n", - " N {exists x.{}({}(\\n.donne(n),exists x.voisin(x)),chat,x)}\n", - "--------------------------------------------------------------------------------------------------------------------------------------------------------<\n", - " S {mange(exists x.{}({}(\\n.donne(n),exists x.voisin(x)),chat,x))}\n", - "8 le chat qui dort est noir\n", - "Found derivation tree with weight 0.25087999999999994\n", - " le chat qui dort est noir\n", - " (N/N) {\\P.exists x.P(x)} N {chat} ((N\\N)/(S\\N)) {{}} (S\\N) {\\n.dormir(n)} ((S\\N)/(N/N)) {{}} (N\\N) {\\n.noir(n)}\n", - " ------------------------------------------>\n", - " (N\\N) {{}(\\n.dormir(n))}\n", - " ----------------------------------------------------<\n", - " N {{}(\\n.dormir(n),chat)}\n", - "------------------------------------------------------------------------------>\n", - " N {exists x.{}(\\n.dormir(n),chat,x)}\n", - " ---------------------------------------->\n", - " (S\\N) {{}(\\n.noir(n))}\n", - "----------------------------------------------------------------------------------------------------------------------<\n", - " S {{}(\\n.noir(n),exists x.{}(\\n.dormir(n),chat,x))}\n", - "1 le chat mange la souris\n", - "Found derivation tree with weight 0.35840000000000005\n", - " le chat mange la souris\n", - " (N/N) {\\P.exists x.P(x)} N {chat} ((S\\N)/N) {\\n m.mange(n,m)} (N/N) {\\P.exists x.P(x)} N {souris}\n", - "------------------------------------>\n", - " N {exists x.chat(x)}\n", - " -------------------------------------->\n", - " N {exists x.souris(x)}\n", - " ------------------------------------------------------------------->\n", - " (S\\N) {\\m.mange(exists x.souris(x),m)}\n", - "-------------------------------------------------------------------------------------------------------<\n", - " S {mange(exists x.souris(x),exists x.chat(x))}\n", - "1 le chat la mange\n", - "Found derivation tree with weight 0.44799999999999995\n", - " le chat la mange\n", - " (N/N) {\\P.exists x.P(x)} N {chat} ((S\\N)/((S\\N)/N)) {{}} ((S\\N)/N) {\\n m.mange(n,m)}\n", - "------------------------------------>\n", - " N {exists x.chat(x)}\n", - " ----------------------------------------------------->\n", - " (S\\N) {{}(\\n m.mange(n,m))}\n", - "-----------------------------------------------------------------------------------------<\n", - " S {{}(\\n m.mange(n,m),exists x.chat(x))}\n", - "1 il la mange\n", - "Found derivation tree with weight 0.5599999999999999\n", - " il la mange\n", - " N {il} ((S\\N)/((S\\N)/N)) {{}} ((S\\N)/N) {\\n m.mange(n,m)}\n", - " ----------------------------------------------------->\n", - " (S\\N) {{}(\\n m.mange(n,m))}\n", - "-------------------------------------------------------------<\n", - " S {{}(\\n m.mange(n,m),il)}\n", - "1 quel chat mange la souris ?\n", - "Found derivation tree with weight 0.2867200000000001\n", - " quel chat mange la souris ?\n", - " ((S/(S\\N))/N) {{}} N {chat} ((S\\N)/N) {\\n m.mange(n,m)} (N/N) {\\P.exists x.P(x)} N {souris} (S\\S) {{}}\n", - "------------------------------>\n", - " (S/(S\\N)) {{}(chat)}\n", - " -------------------------------------->\n", - " N {exists x.souris(x)}\n", - " ------------------------------------------------------------------->\n", - " (S\\N) {\\m.mange(exists x.souris(x),m)}\n", - "------------------------------------------------------------------------------------------------->\n", - " S {{}(chat,\\m.mange(exists x.souris(x),m))}\n", - "-------------------------------------------------------------------------------------------------------------<\n", - " S {{}({}(chat,\\m.mange(exists x.souris(x),m)))}\n", - "1 qui mange la souris ?\n", - "Found derivation tree with weight 0.35840000000000005\n", - " qui mange la souris ?\n", - " (S/(S\\N)) {{}} ((S\\N)/N) {\\n m.mange(n,m)} (N/N) {\\P.exists x.P(x)} N {souris} (S\\S) {{}}\n", - " -------------------------------------->\n", - " N {exists x.souris(x)}\n", - " ------------------------------------------------------------------->\n", - " (S\\N) {\\m.mange(exists x.souris(x),m)}\n", - "----------------------------------------------------------------------------------->\n", - " S {{}(\\m.mange(exists x.souris(x),m))}\n", - "-----------------------------------------------------------------------------------------------<\n", - " S {{}({}(\\m.mange(exists x.souris(x),m)))}\n", - "1 quelle souris mange le chat ?\n", - "Found derivation tree with weight 0.2867200000000001\n", - " quelle souris mange le chat ?\n", - " ((S/(S\\N))/N) {{}} N {souris} ((S\\N)/N) {\\n m.mange(n,m)} (N/N) {\\P.exists x.P(x)} N {chat} (S\\S) {{}}\n", - "-------------------------------->\n", - " (S/(S\\N)) {{}(souris)}\n", - " ------------------------------------>\n", - " N {exists x.chat(x)}\n", - " ----------------------------------------------------------------->\n", - " (S\\N) {\\m.mange(exists x.chat(x),m)}\n", - "------------------------------------------------------------------------------------------------->\n", - " S {{}(souris,\\m.mange(exists x.chat(x),m))}\n", - "-------------------------------------------------------------------------------------------------------------<\n", - " S {{}({}(souris,\\m.mange(exists x.chat(x),m)))}\n", - "1 la souris est mangée par le chat\n", - "Found derivation tree with weight 0.20070400000000002\n", - " la souris est mangée par le chat\n", - " (N/N) {\\P.exists x.P(x)} N {souris} ((S\\N)/Pp) {{}} Pp {\\n.mangé(n)} (((S\\N)\\(S\\N))/N) {{}} (N/N) {\\P.exists x.P(x)} N {chat}\n", - "-------------------------------------->\n", - " N {exists x.souris(x)}\n", - " ----------------------------------->\n", - " (S\\N) {{}(\\n.mangé(n))}\n", - " ------------------------------------>\n", - " N {exists x.chat(x)}\n", - " ------------------------------------------------------------>\n", - " ((S\\N)\\(S\\N)) {{}(exists x.chat(x))}\n", - " -----------------------------------------------------------------------------------------------<\n", - " (S\\N) {{}(exists x.chat(x),{}(\\n.mangé(n)))}\n", - "-------------------------------------------------------------------------------------------------------------------------------------<\n", - " S {{}(exists x.chat(x),{}(\\n.mangé(n)),exists x.souris(x))}\n", - "1 elle est mangée par le chat\n", - "Found derivation tree with weight 0.25088000000000005\n", - " elle est mangée par le chat\n", - " N {elle} ((S\\N)/Pp) {{}} Pp {\\n.mangé(n)} (((S\\N)\\(S\\N))/N) {{}} (N/N) {\\P.exists x.P(x)} N {chat}\n", - " ----------------------------------->\n", - " (S\\N) {{}(\\n.mangé(n))}\n", - " ------------------------------------>\n", - " N {exists x.chat(x)}\n", - " ------------------------------------------------------------>\n", - " ((S\\N)\\(S\\N)) {{}(exists x.chat(x))}\n", - " -----------------------------------------------------------------------------------------------<\n", - " (S\\N) {{}(exists x.chat(x),{}(\\n.mangé(n)))}\n", - "---------------------------------------------------------------------------------------------------------<\n", - " S {{}(exists x.chat(x),{}(\\n.mangé(n)),elle)}\n", - "1 quelle souris est mangée par le chat ?\n", - "Found derivation tree with weight 0.16056320000000004\n", - " quelle souris est mangée par le chat ?\n", - " ((S/(S\\N))/N) {{}} N {souris} ((S\\N)/Pp) {{}} Pp {\\n.mangé(n)} (((S\\N)\\(S\\N))/N) {{}} (N/N) {\\P.exists x.P(x)} N {chat} (S\\S) {{}}\n", - "-------------------------------->\n", - " (S/(S\\N)) {{}(souris)}\n", - " ----------------------------------->\n", - " (S\\N) {{}(\\n.mangé(n))}\n", - " ------------------------------------>\n", - " N {exists x.chat(x)}\n", - " ------------------------------------------------------------>\n", - " ((S\\N)\\(S\\N)) {{}(exists x.chat(x))}\n", - " -----------------------------------------------------------------------------------------------<\n", - " (S\\N) {{}(exists x.chat(x),{}(\\n.mangé(n)))}\n", - "------------------------------------------------------------------------------------------------------------------------------->\n", - " S {{}(souris,{}(exists x.chat(x),{}(\\n.mangé(n))))}\n", - "-------------------------------------------------------------------------------------------------------------------------------------------<\n", - " S {{}({}(souris,{}(exists x.chat(x),{}(\\n.mangé(n)))))}\n", - "1 le chat mange la souris avec ses dents\n", - "Found derivation tree with weight 0.16056320000000004\n", - " le chat mange la souris avec ses dents\n", - " (N/N) {\\P.exists x.P(x)} N {chat} ((S\\N)/N) {\\n m.mange(n,m)} (N/N) {\\P.exists x.P(x)} N {souris} (((S\\N)\\(S\\N))/N) {\\n v.avec(v,n)} (N/N) {\\P.exists x.P(x)} N {dents}\n", - "------------------------------------>\n", - " N {exists x.chat(x)}\n", - " -------------------------------------->\n", - " N {exists x.souris(x)}\n", - " ------------------------------------------------------------------->\n", - " (S\\N) {\\m.mange(exists x.souris(x),m)}\n", - " ------------------------------------->\n", - " N {exists x.dents(x)}\n", - " ------------------------------------------------------------------------->\n", - " ((S\\N)\\(S\\N)) {\\v.avec(v,exists x.dents(x))}\n", - " --------------------------------------------------------------------------------------------------------------------------------------------<\n", - " (S\\N) {avec(\\m.mange(exists x.souris(x),m),exists x.dents(x))}\n", - "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<\n", - " S {avec(\\m.mange(exists x.souris(x),m),exists x.dents(x),exists x.chat(x))}\n", - "1 le chat la mange avec ses dents\n", - "Found derivation tree with weight 0.20070400000000002\n", - " le chat la mange avec ses dents\n", - " (N/N) {\\P.exists x.P(x)} N {chat} ((S\\N)/((S\\N)/N)) {{}} ((S\\N)/N) {\\n m.mange(n,m)} (((S\\N)\\(S\\N))/N) {\\n v.avec(v,n)} (N/N) {\\P.exists x.P(x)} N {dents}\n", - "------------------------------------>\n", - " N {exists x.chat(x)}\n", - " ----------------------------------------------------->\n", - " (S\\N) {{}(\\n m.mange(n,m))}\n", - " ------------------------------------->\n", - " N {exists x.dents(x)}\n", - " ------------------------------------------------------------------------->\n", - " ((S\\N)\\(S\\N)) {\\v.avec(v,exists x.dents(x))}\n", - " ------------------------------------------------------------------------------------------------------------------------------<\n", - " (S\\N) {avec({}(\\n m.mange(n,m)),exists x.dents(x))}\n", - "------------------------------------------------------------------------------------------------------------------------------------------------------------------<\n", - " S {avec({}(\\n m.mange(n,m)),exists x.dents(x),exists x.chat(x))}\n", - "0 avec quoi le chat mange la souris ?\n", - "Pas de dérivation tout court :/\n", - "1 le rat donne un fromage à la souris\n", - "Found derivation tree with weight 0.16056320000000004\n", - " le rat donne un fromage à la souris\n", - " (N/N) {\\P.exists x.P(x)} N {rat} ((S\\N)/N) {\\n m.donne(n,m)} (N/N) {\\P.exists x.P(x)} N {fromage} (((S\\N)\\(S\\N))/N) {\\n v.à(v,n)} (N/N) {\\P.exists x.P(x)} N {souris}\n", - "----------------------------------->\n", - " N {exists x.rat(x)}\n", - " --------------------------------------->\n", - " N {exists x.fromage(x)}\n", - " -------------------------------------------------------------------->\n", - " (S\\N) {\\m.donne(exists x.fromage(x),m)}\n", - " -------------------------------------->\n", - " N {exists x.souris(x)}\n", - " ----------------------------------------------------------------------->\n", - " ((S\\N)\\(S\\N)) {\\v.à(v,exists x.souris(x))}\n", - " -------------------------------------------------------------------------------------------------------------------------------------------<\n", - " (S\\N) {à(\\m.donne(exists x.fromage(x),m),exists x.souris(x))}\n", - "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<\n", - " S {à(\\m.donne(exists x.fromage(x),m),exists x.souris(x),exists x.rat(x))}\n", - "1 un fromage est donné par le rat à la souris\n", - "Found derivation tree with weight 0.08991539200000002\n", - " un fromage est donné par le rat à la souris\n", - " (N/N) {\\P.exists x.P(x)} N {fromage} ((S\\N)/Pp) {{}} Pp {\\n.donné(n)} (((S\\N)\\(S\\N))/N) {{}} (N/N) {\\P.exists x.P(x)} N {rat} (((S\\N)\\(S\\N))/N) {\\n v.à(v,n)} (N/N) {\\P.exists x.P(x)} N {souris}\n", - "--------------------------------------->\n", - " N {exists x.fromage(x)}\n", - " ----------------------------------->\n", - " (S\\N) {{}(\\n.donné(n))}\n", - " ----------------------------------->\n", - " N {exists x.rat(x)}\n", - " ----------------------------------------------------------->\n", - " ((S\\N)\\(S\\N)) {{}(exists x.rat(x))}\n", - " ----------------------------------------------------------------------------------------------<\n", - " (S\\N) {{}(exists x.rat(x),{}(\\n.donné(n)))}\n", - " -------------------------------------->\n", - " N {exists x.souris(x)}\n", - " ----------------------------------------------------------------------->\n", - " ((S\\N)\\(S\\N)) {\\v.à(v,exists x.souris(x))}\n", - " ---------------------------------------------------------------------------------------------------------------------------------------------------------------------<\n", - " (S\\N) {à({}(exists x.rat(x),{}(\\n.donné(n))),exists x.souris(x))}\n", - "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<\n", - " S {à({}(exists x.rat(x),{}(\\n.donné(n))),exists x.souris(x),exists x.fromage(x))}\n", - "0 à quelle souris un fromage est donné par le rat ?\n", - "Pas de dérivation tout court :/\n", - "1 il le donne à la souris\n", - "Found derivation tree with weight 0.25088000000000005\n", - " il le donne à la souris\n", - " N {il} ((S\\N)/((S\\N)/N)) {{}} ((S\\N)/N) {\\n m.donne(n,m)} (((S\\N)\\(S\\N))/N) {\\n v.à(v,n)} (N/N) {\\P.exists x.P(x)} N {souris}\n", - " ----------------------------------------------------->\n", - " (S\\N) {{}(\\n m.donne(n,m))}\n", - " -------------------------------------->\n", - " N {exists x.souris(x)}\n", - " ----------------------------------------------------------------------->\n", - " ((S\\N)\\(S\\N)) {\\v.à(v,exists x.souris(x))}\n", - " ----------------------------------------------------------------------------------------------------------------------------<\n", - " (S\\N) {à({}(\\n m.donne(n,m)),exists x.souris(x))}\n", - "------------------------------------------------------------------------------------------------------------------------------------<\n", - " S {à({}(\\n m.donne(n,m)),exists x.souris(x),il)}\n", - "0 il le lui donne\n", - "Pas de dérivation tout court :/\n", - "1 il souhaite que mon voisin lui donne le chat\n", - "Found derivation tree with weight 0.12845056000000002\n", - " il souhaite que mon voisin lui donne le chat\n", - " N {il} ((S\\N)/N) {\\n m.souhaite(m,n)} (N/S) {{}} (N/N) {\\P.exists x.P(x)} N {voisin} ((S\\N)/(S\\N)) {{}} ((S\\N)/N) {\\n m.donne(n,m)} (N/N) {\\P.exists x.P(x)} N {chat}\n", - " -------------------------------------->\n", - " N {exists x.voisin(x)}\n", - " ------------------------------------>\n", - " N {exists x.chat(x)}\n", - " ----------------------------------------------------------------->\n", - " (S\\N) {\\m.donne(exists x.chat(x),m)}\n", - " ------------------------------------------------------------------------------------->\n", - " (S\\N) {{}(\\m.donne(exists x.chat(x),m))}\n", - " ---------------------------------------------------------------------------------------------------------------------------<\n", - " S {{}(\\m.donne(exists x.chat(x),m),exists x.voisin(x))}\n", - " --------------------------------------------------------------------------------------------------------------------------------------->\n", - " N {{}({}(\\m.donne(exists x.chat(x),m),exists x.voisin(x)))}\n", - " ----------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n", - " (S\\N) {\\m.souhaite(m,{}({}(\\m.donne(exists x.chat(x),m),exists x.voisin(x))))}\n", - "-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<\n", - " S {souhaite(il,{}({}(\\m.donne(exists x.chat(x),m),exists x.voisin(x))))}\n", - "1 il souhaite donner le chat à mon voisin\n", - "Found derivation tree with weight 0.16056320000000004\n", - " il souhaite donner le chat à mon voisin\n", - " N {il} ((S\\N)/N) {\\n m.souhaite(m,n)} (N/N) {\\n.donner(n)} (N/N) {\\P.exists x.P(x)} N {chat} (((S\\N)\\(S\\N))/N) {\\n v.à(v,n)} (N/N) {\\P.exists x.P(x)} N {voisin}\n", - " ------------------------------------>\n", - " N {exists x.chat(x)}\n", - " ---------------------------------------------------------->\n", - " N {donner(exists x.chat(x))}\n", - " ------------------------------------------------------------------------------------------>\n", - " (S\\N) {\\m.souhaite(m,donner(exists x.chat(x)))}\n", - " -------------------------------------->\n", - " N {exists x.voisin(x)}\n", - " ----------------------------------------------------------------------->\n", - " ((S\\N)\\(S\\N)) {\\v.à(v,exists x.voisin(x))}\n", - " -----------------------------------------------------------------------------------------------------------------------------------------------------------------<\n", - " (S\\N) {à(\\m.souhaite(m,donner(exists x.chat(x))),exists x.voisin(x))}\n", - "-------------------------------------------------------------------------------------------------------------------------------------------------------------------------<\n", - " S {à(\\m.souhaite(m,donner(exists x.chat(x))),exists x.voisin(x),il)}\n", - "0 le chat de mon voisin pourchasse et attrape la souris\n", - "Pas de dérivation tout court :/\n", - "2 la souris dort et le chat de mon voisin attrape la souris\n", - "Found derivation tree with weight 0.05035261952\n", - " la souris dort et le chat de mon voisin attrape la souris\n", - " (N/N) {\\P.exists x.P(x)} N {souris} (S\\N) {\\n.dormir(n)} ((S/S)\\S) {\\x y.et(x,y)} (N/N) {\\P.exists x.P(x)} N {chat} ((N/N)\\N) {\\n m.de(n,m)} (N/N) {\\P.exists x.P(x)} N {voisin} ((S\\N)/N) {\\n m.attrappe(m,n)} (N/N) {\\P.exists x.P(x)} N {souris}\n", - "-------------------------------------->\n", - " N {exists x.souris(x)}\n", - "------------------------------------------------------------<\n", - " S {dormir(exists x.souris(x))}\n", - "--------------------------------------------------------------------------------------<\n", - " (S/S) {\\y.et(dormir(exists x.souris(x)),y)}\n", - " ------------------------------------<\n", - " (N/N) {\\m.de(chat,m)}\n", - " -------------------------------------->\n", - " N {exists x.voisin(x)}\n", - " -------------------------------------------------------------------------->\n", - " N {de(chat,exists x.voisin(x))}\n", - " ---------------------------------------------------------------------------------------------------->\n", - " N {exists x.de(chat,exists x.voisin(x),x)}\n", - " -------------------------------------->\n", - " N {exists x.souris(x)}\n", - " ---------------------------------------------------------------------->\n", - " (S\\N) {\\m.attrappe(m,exists x.souris(x))}\n", - " --------------------------------------------------------------------------------------------------------------------------------------------------------------------------<\n", - " S {attrappe(exists x.de(chat,exists x.voisin(x),x),exists x.souris(x))}\n", - "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n", - " S {et(dormir(exists x.souris(x)),attrappe(exists x.de(chat,exists x.voisin(x),x),exists x.souris(x)))}\n", - "1 le chat dort et la souris dort\n", - "Found derivation tree with weight 0.17561599999999997\n", - " le chat dort et la souris dort\n", - " (N/N) {\\P.exists x.P(x)} N {chat} (S\\N) {\\n.dormir(n)} ((S/S)\\S) {\\x y.et(x,y)} (N/N) {\\P.exists x.P(x)} N {souris} (S\\N) {\\n.dormir(n)}\n", - "------------------------------------>\n", - " N {exists x.chat(x)}\n", - "----------------------------------------------------------<\n", - " S {dormir(exists x.chat(x))}\n", - "------------------------------------------------------------------------------------<\n", - " (S/S) {\\y.et(dormir(exists x.chat(x)),y)}\n", - " -------------------------------------->\n", - " N {exists x.souris(x)}\n", - " ------------------------------------------------------------<\n", - " S {dormir(exists x.souris(x))}\n", - "------------------------------------------------------------------------------------------------------------------------------------------------>\n", - " S {et(dormir(exists x.chat(x)),dormir(exists x.souris(x)))}\n", - "2 le chat et la souris dorment\n", - "Found derivation tree with weight 0.25088\n", - " le chat et la souris dorment\n", - " (N/N) {\\P.exists x.P(x)} N {chat} ((N/N)\\N) {\\n m.et(n,m)} (N/N) {\\P.exists x.P(x)} N {souris} (S\\N) {\\n.dormir(n)}\n", - " ------------------------------------<\n", - " (N/N) {\\m.et(chat,m)}\n", - " -------------------------------------->\n", - " N {exists x.souris(x)}\n", - " -------------------------------------------------------------------------->\n", - " N {et(chat,exists x.souris(x))}\n", - "---------------------------------------------------------------------------------------------------->\n", - " N {exists x.et(chat,exists x.souris(x),x)}\n", - "--------------------------------------------------------------------------------------------------------------------------<\n", - " S {dormir(exists x.et(chat,exists x.souris(x),x))}\n", - "2 le chat et la souris dorment\n", - "Found derivation tree with weight 0.25088\n", - " le chat et la souris dorment\n", - " (N/N) {\\P.exists x.P(x)} N {chat} ((N/N)\\N) {\\n m.et(n,m)} (N/N) {\\P.exists x.P(x)} N {souris} (S\\N) {\\n.dormir(n)}\n", - " ------------------------------------<\n", - " (N/N) {\\m.et(chat,m)}\n", - " -------------------------------------->\n", - " N {exists x.souris(x)}\n", - " -------------------------------------------------------------------------->\n", - " N {et(chat,exists x.souris(x))}\n", - "---------------------------------------------------------------------------------------------------->\n", - " N {exists x.et(chat,exists x.souris(x),x)}\n", - "--------------------------------------------------------------------------------------------------------------------------<\n", - " S {dormir(exists x.et(chat,exists x.souris(x),x))}\n" - ] - } - ], + "source": [ + "We create our lexicon using the data from the server" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], "source": [ "# Catégories primitives et familles\n", - "primitives = ['S', 'N', 'Pp']\n", + "primitives = ['S', 'N', 'Pp', 'pN']\n", "V = augParseCategory(\"S\\\\N\", primitives = primitives, families={})\n", "families = {'V': V}\n", "\n", @@ -699,131 +261,1207 @@ "#print(table.keys())\n", "\n", "# On le convertit en Lexique pondéré\n", - "pe = to_pseudo_entries(table, consider_semantics = True)\n", + "pe = to_pseudo_entries(table, consider_semantics = False)\n", "#print(pe)\n", "wEntries = to_wlex_entries(pseudo_entries= pe, primitives= primitives, families= families)\n", "#print([list(map(lambda x: f\"{k} : \"+ str(x) + str(x._semantics), L)) for k, L in wEntries.items()])\n", "lex = WeighedLexicon(start= 'S', primitives= primitives, families= families, entries= wEntries)\n", "\n", "\n", - "# On récupère le nombre de mots qui ont été définis\n", - "# n = len(table['MOT'])\n", - "\n", - "# On donne la liste des catégories primitives\n", - "# lexstring = ':- S,N,Pp\\n'\n", - "# On ajoute la notation V pour N\\S\n", - "# lexstring += 'V :: S\\\\N\\n'\n", - "\n", - "# On lis les données depuis le tableur en une chaine de caractère parsable\n", - "#for i in range(n):\n", - "# for j in range(3):\n", - "# if isinstance(table['Cat'+str(j)][i],str):\n", - "# for mot in table['MOT'][i].split('/'):\n", - "# lexstring+=mot+' => ' + table['Cat'+str(j)][i] + '\\n'\n", - "\n", - "# Pour inverser les slash dans le lexicon\n", - "#lexstring = lexstring.replace('\\\\','#').replace('/','\\\\').replace('#','/')\n", - "\n", - "# On crée notre lexique\n", - "# lex = lexicon.fromstring(lexstring)\n", - "\n", "# On crée le parser, on donne l'ensemble des règles qu'il est cencé connaître\n", - "parser = chart.CCGChartParser(lex, chart.DefaultRuleSet)\n", - "#parser = chart.CCGChartParser(lex, chart.ApplicationRuleSet)\n", + "from nltk.ccg.combinator import (\n", + " BackwardApplication,\n", + " BackwardBx,\n", + " BackwardComposition,\n", + " BackwardSx,\n", + " ForwardApplication,\n", + " ForwardComposition,\n", + " ForwardSubstitution\n", + ")\n", + "rulesC = [ForwardApplication,BackwardApplication] \n", + "rulesC += [ForwardComposition,BackwardComposition,BackwardBx]\n", + "rulesC += [ForwardSubstitution,BackwardSx]\n", + "rulesR = [BinaryCombinatorRule(c) for c in rulesC]\n", + "# chart.ApplicationRuleSet for only < and >\n", "\n", - "printTotal=True\n", - "printDerivations=not printTotal\n", - "\n", - "# On lit les phrases dans le fichier\n", - "with open('phrases.txt') as f:\n", - " lines = f.readlines()\n", - "\n", - " lines.append(\"le chat et la souris dorment\")\n", - " \n", - " for phrase in lines:\n", - " # On met tout en minuscule\n", - " phrase = phrase.lower().strip()\n", - " if printDerivations:\n", - " print(\"=\"*77)\n", - " print('#',phrase)\n", - " # lex = lexicon.fromstring(lexstring)\n", - " parser = chart.CCGChartParser(lex, chart.ApplicationRuleSet)\n", - "\n", - " # Et on affiche tous les arbres de dérivation trouvés\n", - " i=0\n", - " for parse in parser.parse(phrase.split()):\n", - " i+=1\n", - " if printDerivations:\n", - " chart.printCCGDerivation(parse)\n", - " \n", - " if printTotal:\n", - " print(i,phrase)\n", - " \n", - " \n", - " # On affiche la dérivation la meilleure pour l'arbre\n", - " if (i==0):\n", - " print(\"Pas de dérivation tout court :/\")\n", - " else:\n", - "\n", - " t,d = bestTree(phrase.split(), lex, chart.ApplicationRuleSet)\n", - " print(\"Found derivation tree with weight\",d)\n", - " chart.printCCGDerivation(t)" + "parser = chart.CCGChartParser(lex, rulesR)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "On lit les phrases depuis le fichier `phrases.txt`, et pour chacune, on imprime le nombre de dérivations trouvées, ainsi que le meilleur arbre de dérivation (i.e. de meilleur poids)" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "? => (S\\S) {{}}\n", - "attrape => ((S\\N)/N) {\\n m.attrappe(m,n)}\n", - "avec => (((S\\N)\\(S\\N))/N) {\\n v.avec(v,n)}\n", - "chat => N {chat}\n", - "de => ((N/N)\\N) {\\n m.de(n,m)}\n", - "dents => N {dents}\n", - "donne => (S\\N) {\\n.donne(n)} | ((S\\N)/N) {\\n m.donne(n,m)}\n", - "donner => N {donner} | (N/N) {\\n.donner(n)}\n", - "donné => Pp {\\n.donné(n)}\n", - "dorment => (S\\N) {\\n.dormir(n)}\n", - "dort => (S\\N) {\\n.dormir(n)}\n", - "elle => N {elle}\n", - "est => ((S\\N)/Pp) {{}} | ((S\\N)/(N/N)) {{}} | ((S\\N)/(N\\N)) {{}}\n", - "et => ((N/N)\\N) {\\n m.et(n,m)} | ((S/S)\\S) {\\x y.et(x,y)} | (((S\\N)/(S\\N))\\(S\\N)) {\\v w n.et(v,w,n)}\n", - "fromage => N {fromage}\n", - "il => N {il}\n", - "la => ((S\\N)/((S\\N)/N)) {{}} | (N/N) {\\P.exists x.P(x)}\n", - "le => ((S\\N)/((S\\N)/N)) {{}} | (N/N) {\\P.exists x.P(x)}\n", - "lui => ((S\\N)/(S\\N)) {{}}\n", - "mange => (S\\N) {\\n.mange(n)} | ((S\\N)/N) {\\n m.mange(n,m)}\n", - "mangé => Pp {\\n.mangé(n)}\n", - "mangée => Pp {\\n.mangé(n)}\n", - "mon => (N/N) {\\P.exists x.P(x)}\n", - "méchant => (N/N) {\\n.méchant(n)} | (N\\N) {\\n.méchant(n)}\n", - "noir => (N\\N) {\\n.noir(n)} | (N/N) {\\n.noir(n)}\n", - "paisiblement => ((S\\N)\\(S\\N)) {\\v n.paisiblement(v,n)}\n", - "par => (((S\\N)\\(S\\N))/N) {{}}\n", - "pourchasse => ((S\\N)/N) {\\n m.pourchasse(m,n)}\n", - "que => ((N\\N)/S) {{}} | (N/S) {{}}\n", - "quel => (((((S\\N)\\(S\\N))/N)\\(S/S))/N) {{}} | ((S/(S\\N))/N) {{}}\n", - "quelle => (((((S\\N)\\(S\\N))/N)\\(S/S))/N) {{}} | ((S/(S\\N))/N) {{}}\n", - "qui => ((N\\N)/(S\\N)) {{}} | (S/(S\\N)) {{}}\n", - "quoi => (((S/S)\\(((S\\N)\\(S\\N))/N))/N) {{}}\n", - "rat => N {rat}\n", - "ses => (N/N) {\\P.exists x.P(x)}\n", - "souhaite => ((S\\N)/N) {\\n m.souhaite(m,n)}\n", - "souris => N {souris}\n", - "sœur => N {soeur}\n", - "très => ((N/N)/(N/N)) {{}}\n", - "un => (N/N) {\\P.exists x.P(x)}\n", - "voisin => N {voisin}\n", - "à => (((S\\N)\\(S\\N))/N) {\\n v.à(v,n)}\n" + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n", + "2 found derivation for sentence: le méchant chat dort\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + "----------------->B\n", + " (N/pN)\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "==> 2 0\n", + "==> 2 1\n", + "==> 2 2\n", + "==> 3 0\n", + "==> 3 1\n", + "==> 4 0\n", + "Edge count: 1\n", + "Best derivation tree has weight 0.24957917865181148\n", + " le méchant chat dort\n", + " (N/pN) (pN/pN) pN (S\\N)\n", + " --------------->\n", + " pN\n", + "----------------------->\n", + " N\n", + "------------------------------<\n", + " S\n", + "##########################################\n" ] } ], + "source": [ + "# On lit les phrases dans le fichier\n", + "with open('phrases.txt') as f:\n", + " lines = f.readlines()\n", + "\n", + " # On ajoute des phrases de test\n", + " lines.append(\"le chat et la souris dorment\")\n", + " \n", + " for phrase in lines:\n", + " # On met tout en minuscule\n", + " phrase = phrase.lower().strip()\n", + " phrase = \"le méchant chat dort\"\n", + " \n", + " # On compte les arbres de dérivation trouvés\n", + " i = len(list(parser.parse(phrase.split())))\n", + " print(i, \"found derivation for sentence:\",phrase)\n", + " g = parser.parse(phrase.split())\n", + " for t in g:\n", + " chart.printCCGDerivation(t)\n", + " \n", + " # On affiche la dérivation la meilleure pour l'arbre\n", + " if (i != 0):\n", + " t,d = bestTree(phrase.split(), lex, rulesC)\n", + " print(\"Best derivation tree has weight\",d)\n", + " chart.printCCGDerivation(t)\n", + " \n", + " print(\"#\"*42)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "print(lex)" ] @@ -831,9 +1469,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "venv", "language": "python", - "name": "python3" + "name": "venv" }, "language_info": { "codemirror_mode": { @@ -845,7 +1483,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.1" + "version": "3.11.2" } }, "nbformat": 4,