Skip to content

Commit

Permalink
First try links between word senses
Browse files Browse the repository at this point in the history
  • Loading branch information
hmuniz committed Feb 9, 2020
1 parent e230fc0 commit 33a651e
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 23 deletions.
43 changes: 42 additions & 1 deletion templates.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
59 changes: 37 additions & 22 deletions templates/synset.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
{/template}


{template word-relations}
{if isNonnull($rels)}
{foreach $r in $rels}
{if isFirst($r)}({/if}
{if not isFirst($r)}, {/if}
<a title="{$r.pointer} {$r.target_word} {$r.target_synset}" href="synset?id={$r.target_synset}"> {$r.symbol} </a>
{if isLast($r)}){/if}
{/foreach}
{/if}
{/template}


{template synset}
{call header}
{param extratitle: $doc_id /}
Expand Down Expand Up @@ -65,6 +77,9 @@
{foreach $w in $word_en}
{if not isFirst($w)}{sp}&bull;{sp}{/if}
<span class="enword">{$w}</span>
{call word-relations}
{param rels: wordrel($synset, $w) /}
{/call}
{/foreach}
</p>

Expand Down Expand Up @@ -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}

</ul>
Expand Down

0 comments on commit 33a651e

Please sign in to comment.