From 33a651e243ba9a16ec8ad6515be50a1a3db41a6b Mon Sep 17 00:00:00 2001 From: Henrique Muniz Date: Sun, 9 Feb 2020 20:26:36 -0300 Subject: [PATCH] First try links between word senses --- templates.lisp | 43 ++++++++++++++++++++++++++++++- templates/synset.tmpl | 59 +++++++++++++++++++++++++++---------------- 2 files changed, 79 insertions(+), 23 deletions(-) diff --git a/templates.lisp b/templates.lisp index 15b9420..db0d3f8 100644 --- a/templates.lisp +++ b/templates.lisp @@ -144,6 +144,45 @@ in dealing with checkboxes." (defun get-sense-weight (s) (cadr (split-sequence #\: s))) +(defun is-synset-rel (rels) + (remove-if (lambda (x) (getf x :|source_word|)) + rels)) + + +(defparameter *rel-symbols* (alexandria:plist-hash-table '(:|wn30_en_antonymOf| "ant" + :|wn30_en_causes| "cause" + :|wn30_en_classifiedByRegion| "mr" + :|wn30_en_classifiedByTopic| "mt" + :|wn30_en_classifiedByUsage| "mu" + :|wn30_en_classifiesByRegion| "dr" + :|wn30_en_classifiesByTopic| "dt" + :|wn30_en_classifiesByUsage| "du" + :|wn30_en_derivationallyRelated| "drf" + :|wn30_en_participleOf| "pv" + :|wn30_en_pertainsTo| "pe" + :|wn30_en_property| "prp" + :|wn30_en_sameVerbGroupAs| "vg" + :|wn30_en_seeAlso| "see") :test #'equal)) + +(defun aux-filter-sense-rel (rel links word) + (loop for link in links + when (equal (getf link :|source_word|) word) + collect (cons :|symbol| + (cons (gethash rel *rel-symbols*) + link)))) + +(defun filter-sense-rel (synset word) + + (let ((relations '(:|wn30_en_classifiedByRegion| :|wn30_en_classifiedByTopic| + :|wn30_en_classifiedByUsage| :|wn30_en_classifiesByRegion| + :|wn30_en_classifiesByTopic| :|wn30_en_classifiesByUsage| + :|wn30_en_sameVerbGroupAs| :|wn30_en_seeAlso| + :|wn30_en_derivationallyRelated| :|wn30_en_antonymOf| + :|wn30_en_pertainsTo| :|wn30_en_property| + :|wn30_en_participleOf| :|wn30_en_causes|))) + (loop for rel in relations + append (aux-filter-sense-rel rel (getf synset rel) word)))) + (defun setup-templates () (closure-template:with-user-functions (("issynset" #'is-synset) @@ -170,7 +209,9 @@ in dealing with checkboxes." ("ismember" #'is-member) ("synsetworden" #'get-synset-word-en) ("synsetword" #'get-synset-word) - ("synsetgloss" #'get-synset-gloss)) + ("synsetgloss" #'get-synset-gloss) + ("synsetrel" #'is-synset-rel) + ("wordrel" #'filter-sense-rel)) (walk-directory (merge-pathnames *templates-directory* *basedir*) (lambda (f) diff --git a/templates/synset.tmpl b/templates/synset.tmpl index bf5236d..06db5ed 100644 --- a/templates/synset.tmpl +++ b/templates/synset.tmpl @@ -24,6 +24,18 @@ {/template} +{template word-relations} + {if isNonnull($rels)} + {foreach $r in $rels} + {if isFirst($r)}({/if} + {if not isFirst($r)}, {/if} + {$r.symbol} + {if isLast($r)}){/if} + {/foreach} + {/if} +{/template} + + {template synset} {call header} {param extratitle: $doc_id /} @@ -65,6 +77,9 @@ {foreach $w in $word_en} {if not isFirst($w)}{sp}•{sp}{/if} {$w} + {call word-relations} + {param rels: wordrel($synset, $w) /} + {/call} {/foreach}

@@ -239,112 +254,112 @@ {call describe-relation} {param description: 'Hypernym of' /} - {param synsets: $wn30_en_hypernymof /} + {param synsets: synsetrel($wn30_en_hypernymof) /} {/call} {call describe-relation} {param description: 'Hyponym of' /} - {param synsets: $wn30_en_hyponymof /} + {param synsets: synsetrel($wn30_en_hyponymof) /} {/call} {call describe-relation} {param description: 'Part holonym of' /} - {param synsets: $wn30_en_partholonymof /} + {param synsets: synsetrel($wn30_en_partholonymof) /} {/call} {call describe-relation} {param description: 'Part meronym of' /} - {param synsets: $wn30_en_partmeronymof /} + {param synsets: synsetrel($wn30_en_partmeronymof) /} {/call} {call describe-relation} {param description: 'Member holonym of' /} - {param synsets: $wn30_en_memberholonymof /} + {param synsets: synsetrel($wn30_en_memberholonymof) /} {/call} {call describe-relation} {param description: 'Member meronym of' /} - {param synsets: $wn30_en_membermeronymof /} + {param synsets: synsetrel($wn30_en_membermeronymof) /} {/call} {call describe-relation} {param description: 'Substance holonym of' /} - {param synsets: $wn30_en_substanceholonymof /} + {param synsets: synsetrel($wn30_en_substanceholonymof) /} {/call} {call describe-relation} {param description: 'Substance meronym of' /} - {param synsets: $wn30_en_substancemeronymof /} + {param synsets: synsetrel($wn30_en_substancemeronymof) /} {/call} {call describe-relation} {param description: 'Similar to' /} - {param synsets: $wn30_en_similarto /} + {param synsets: synsetrel($wn30_en_similarto) /} {/call} {call describe-relation} {param description: 'See also' /} - {param synsets: $wn30_en_seealso /} + {param synsets: synsetrel($wn30_en_seealso) /} {/call} {call describe-relation} {param description: 'Instance of' /} - {param synsets: $wn30_en_instanceof /} + {param synsets: synsetrel($wn30_en_instanceof) /} {/call} {call describe-relation} {param description: 'Has instance' /} - {param synsets: $wn30_en_hasinstance /} + {param synsets: synsetrel($wn30_en_hasinstance) /} {/call} {call describe-relation} {param description: 'Attribute' /} - {param synsets: $wn30_en_attribute /} + {param synsets: synsetrel($wn30_en_attribute) /} {/call} {call describe-relation} {param description: 'Causes' /} - {param synsets: $wn30_en_causes /} + {param synsets: synsetrel($wn30_en_causes) /} {/call} {call describe-relation} {param description: 'Same verb group as' /} - {param synsets: $wn30_en_sameverbgroupas /} + {param synsets: synsetrel($wn30_en_sameverbgroupas) /} {/call} {call describe-relation} {param description: 'Entails' /} - {param synsets: $wn30_en_entails /} + {param synsets: synsetrel($wn30_en_entails) /} {/call} {call describe-relation} {param description: 'Classified by region' /} - {param synsets: $wn30_en_classifiedbyregion /} + {param synsets: synsetrel($wn30_en_classifiedbyregion) /} {/call} {call describe-relation} {param description: 'Classified by topic' /} - {param synsets: $wn30_en_classifiedbytopic /} + {param synsets: synsetrel($wn30_en_classifiedbytopic) /} {/call} {call describe-relation} {param description: 'Classified by usage' /} - {param synsets: $wn30_en_classifiedbyusage /} + {param synsets: synsetrel($wn30_en_classifiedbyusage) /} {/call} {call describe-relation} {param description: 'Classifies by region' /} - {param synsets: $wn30_en_classifiesbyregion /} + {param synsets: synsetrel($wn30_en_classifiesbyregion) /} {/call} {call describe-relation} {param description: 'Classifies by topic' /} - {param synsets: $wn30_en_classifiesbytopic /} + {param synsets: synsetrel($wn30_en_classifiesbytopic) /} {/call} {call describe-relation} {param description: 'Classifies by usage' /} - {param synsets: $wn30_en_classifiesbyusage /} + {param synsets: synsetrel($wn30_en_classifiesbyusage) /} {/call}