Skip to content

Commit

Permalink
[feat] implement homophone-based pun detector
Browse files Browse the repository at this point in the history
  • Loading branch information
pingpingy1 committed Dec 4, 2023
1 parent 3b1da67 commit 8b7e9fe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
17 changes: 16 additions & 1 deletion hopre/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,22 @@ def hopre() -> None:
f'The two incompatible interpretations of "{context1}" and "{context2}" are resolved with the homonym "{homonym}"!'
)
else:
print("I don't think this is a joke...")
result = pthread.query(
f"homophonePun({sentences},Homophone1,Homophone2,Context1,Context2)"
)
if result:
assert isinstance(result, list)
fst = result[0]
context1 = " ".join(fst["Context1"])
context2 = " ".join(fst["Context2"])
homophone1 = " ".join(fst["Homophone1"])
homophone2 = " ".join(fst["Homophone2"])
print("I get it!")
print(
f'The two incompatible interpretations of "{context1}" and "{context2}" are resolved with the homophones "{homophone1}" and "{homophone2}"!'
)
else:
print("I don't think that is a joke...")

print()
if input("Press enter to continue or q to exit...").endswith("q"):
Expand Down
18 changes: 18 additions & 0 deletions hopre/englishAnalysis/englishLexicon.pl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@

lexEntry(noun,[symbol:tomato,syntax:[tomato]]).
lexEntry(noun,[symbol:salad,syntax:[salad]]).
lexEntry(noun,[symbol:computer,syntax:[computer]]).
lexEntry(noun,[symbol:doctor,syntax:[doctor]]).
lexEntry(noun,[symbol:bite,syntax:[bite]]).
lexEntry(noun,[symbol:byte,syntax:[byte]]).


/*========================================================================
Expand Down Expand Up @@ -196,7 +200,12 @@

lexEntry(tv,[symbol:have,syntax:[have],inf:inf,num:sg]).
lexEntry(tv,[symbol:have,syntax:[has],inf:fin,num:sg]).
lexEntry(tv,[symbol:have,syntax:[have],inf:fin,num:sg]).
lexEntry(tv,[symbol:have,syntax:[have],inf:fin,num:pl]).
lexEntry(tv,[symbol:have,syntax:[had],inf:inf,num:sg]).
lexEntry(tv,[symbol:have,syntax:[had],inf:inf,num:pl]).
lexEntry(tv,[symbol:have,syntax:[had],inf:fin,num:sg]).
lexEntry(tv,[symbol:have,syntax:[had],inf:fin,num:pl]).

lexEntry(tv,[symbol:kill,syntax:[kill],inf:inf,num:sg]).
lexEntry(tv,[symbol:kill,syntax:[kills],inf:fin,num:sg]).
Expand Down Expand Up @@ -232,6 +241,15 @@
lexEntry(tv,[symbol:see,syntax:[saw],inf:fin,num:sg]).
lexEntry(tv,[symbol:see,syntax:[saw],inf:fin,num:pl]).

lexEntry(tv,[symbol:goto,syntax:[go,to],inf:inf,num:sg]).
lexEntry(tv,[symbol:goto,syntax:[go,to],inf:fin,num:sg]).
lexEntry(tv,[symbol:goto,syntax:[goes,to],inf:fin,num:sg]).
lexEntry(tv,[symbol:goto,syntax:[goes,to],inf:fin,num:pl]).
lexEntry(tv,[symbol:goto,syntax:[went,to],inf:inf,num:sg]).
lexEntry(tv,[symbol:goto,syntax:[went,to],inf:inf,num:pl]).
lexEntry(tv,[symbol:goto,syntax:[went,to],inf:fin,num:sg]).
lexEntry(tv,[symbol:goto,syntax:[went,to],inf:fin,num:pl]).


/*========================================================================
Copula
Expand Down
13 changes: 12 additions & 1 deletion hopre/pun_detection.pl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,15 @@
similar(HomonymPhrase,Context1),
append([_,Context2,_],AllWords),
similar(HomonymPhrase,Context2),
dissimilar(Context1,Context2).
dissimilar(Context1,Context2).

homophonePun(Sentences,Homophone1,Homophone2,Context1,Context2):-
allTexts(Sentences),
append(Sentences,AllWords),
append([_,Homophone1,_],AllWords),
homophone(Homophone1,Homophone2),
append([_,Context1,_],AllWords),
similar(Homophone1,Context1),
append([_,Context2,_],AllWords),
similar(Homophone2,Context2),
dissimilar(Context1,Context2).

0 comments on commit 8b7e9fe

Please sign in to comment.