This more or less works - still fine tuning to do.
This commit is contained in:
parent
fb00ec31a0
commit
f98fac03a9
2 changed files with 133 additions and 100 deletions
|
|
@ -1,27 +1,95 @@
|
|||
(ns wwui.propositions-test
|
||||
(:require [clojure.test :refer :all]
|
||||
[wwui.propositions :refer :all]))
|
||||
[wwui.propositions :refer :all]
|
||||
[taoensso.timbre :as log :refer [set-level!]]))
|
||||
|
||||
(log/set-level! :error)
|
||||
|
||||
(deftest reparser-tests
|
||||
(testing "Simplest constructs"
|
||||
(is (= (recursive-descent-parser [] grammar :noun) nil))
|
||||
(is (= (reparse [] grammar :noun) nil))
|
||||
(is
|
||||
(=
|
||||
(recursive-descent-parser (pos-tag (tokenize "Brutus killed Caesar")) grammar :noun)
|
||||
(reparse [["Brutus" "NNP"] ["killed" "VBD"] ["Caesar" "NNP"]] grammar :noun)
|
||||
'(((["Brutus" "NNP"]) :noun) ["killed" "VBD"] ["Caesar" "NNP"])))
|
||||
(is
|
||||
(=
|
||||
(recursive-descent-parser (pos-tag (tokenize "Brutus killed Caesar")) grammar :noun-phrase)
|
||||
(reparse [["Brutus" "NNP"] ["killed" "VBD"] ["Caesar" "NNP"]] grammar :noun-phrase)
|
||||
'((((["Brutus" "NNP"]) :noun) :nown-phrase) ["killed" "VBD"] ["Caesar" "NNP"])))
|
||||
(is
|
||||
(=
|
||||
(recursive-descent-parser (pos-tag (tokenize "The Forum")) grammar :noun-phrase)
|
||||
(((["The" "DT"]["Forum" "NNP"]) :noun-phrase))))
|
||||
(reparse [["The" "DT"] ["Forum" "NNP"]] grammar :noun-phrase)
|
||||
'(((["The" "DT"]["Forum" "NNP"]) :noun-phrase))))
|
||||
(is
|
||||
(=
|
||||
(recursive-descent-parser (pos-tag (tokenize "killed Caesar")) grammar :verb)
|
||||
(((["killed" "VBN"]) :verb) ["Caesar" "NNP"])))
|
||||
(reparse [["killed" "VBD"] ["Caesar" "NNP"]] grammar :verb)
|
||||
'(((["killed" "VBD"]) :verb) ["Caesar" "NNP"])))
|
||||
(is
|
||||
(=
|
||||
(recursive-descent-parser (pos-tag (tokenize "in the Forum")) grammar :locator)
|
||||
(((["in" "IN"]["the" "DT"]["Forum" "NNP"]) :locator) )))))
|
||||
(reparse [["in" "IN"] ["the" "DT"] ["Forum" "NNP"]] grammar :locator)
|
||||
'(((["in" "IN"] ((["the" "DT"] ((["Forum" "NNP"]) :noun)) :noun-phrase)) :locator))))
|
||||
(is
|
||||
(=
|
||||
(reparse [["in" "IN"] ["the" "DT"] ["forum" "NN"]] grammar :locator)
|
||||
'(((["in" "IN"] ((["the" "DT"] ((["forum" "NN"]) :noun)) :noun-phrase)) :locator))))
|
||||
)
|
||||
(testing "collections"
|
||||
(is
|
||||
(= (count (reparse (pos-tag (tokenize "brave, noble")) grammar :adjectives)) 1)
|
||||
"Currently, lists of adjectives are not being recognised, and this fails.")
|
||||
(is
|
||||
(= (count (reparse (pos-tag (tokenize "cruelly and wickedly")) grammar :adverbs)) 1)
|
||||
"Currently, lists of adverbs are not being recognised, and this fails."))
|
||||
(testing "locators"
|
||||
(is
|
||||
(=
|
||||
(reparse [["in" "IN"] ["the" "DT"] ["forum" "NN"]] grammar :locator)
|
||||
'(((["in" "IN"] ((["the" "DT"] ((["forum" "NN"]) :noun)) :noun-phrase)) :locator)))
|
||||
"Positional locator")
|
||||
(is
|
||||
(=
|
||||
(count
|
||||
(reparse
|
||||
[["on" "IN"] ["the" "DT"] ["ides" "NNS"] ["of" "IN"] ["March" "NNP"]]
|
||||
grammar
|
||||
:locator))
|
||||
1)
|
||||
"Temporal locator: currently, 'of March' is not being recognised as part of the locator, so this is failing.")
|
||||
(is
|
||||
(=
|
||||
(reparse [["in" "IN"] ["the" "DT"] ["forum" "NN"]] grammar :locator)
|
||||
'(((((["in" "IN"] ((["the" "DT"] ((["forum" "NN"]) :noun)) :noun-phrase)) :locator)) :locators)))
|
||||
"Single locator as locators")
|
||||
)
|
||||
(testing "propositions"
|
||||
(is
|
||||
(=
|
||||
(reparse [["Brutus" "NNP"] ["killed" "VBD"] ["Caesar" "NNP"]] grammar :proposition)
|
||||
'(((((((((["Brutus" "NNP"]) :noun)) :noun-phrase)) :subject)
|
||||
((((["killed" "VBD"]) :verb)) :verb-phrase)
|
||||
((((((["Caesar" "NNP"]) :noun)) :noun-phrase)) :object)) :proposition))
|
||||
))
|
||||
(is
|
||||
(=
|
||||
(reparse
|
||||
[["Proud" "JJ"] ["Brutus" "NNP"] ["killed" "VBD"] ["noble" "JJ"] ["Caesar" "NNP"]]
|
||||
grammar :proposition)
|
||||
'(((((((((((["Proud" "JJ"]) :adjective)) :adjectives)
|
||||
((["Brutus" "NNP"]) :noun)) :noun-phrase)) :subject)
|
||||
((((["killed" "VBD"]) :verb)) :verb-phrase)
|
||||
((((((((["noble" "JJ"]) :adjective)) :adjectives)
|
||||
((["Caesar" "NNP"]) :noun)) :noun-phrase)) :object)) :proposition))
|
||||
) "Single adjectives")
|
||||
(is
|
||||
(=
|
||||
(reparse
|
||||
[["Proud" "JJ"] ["Brutus" "NNP"] ["brutally" "RB"] ["killed" "VBD"] ["noble" "JJ"] ["Caesar" "NNP"]]
|
||||
grammar :proposition)
|
||||
'(((((((((((["Proud" "JJ"]) :adjective)) :adjectives)
|
||||
((["Brutus" "NNP"]) :noun)) :noun-phrase)) :subject)
|
||||
((((((["brutally" "RB"]) :adverb)) :adverbs)
|
||||
((["killed" "VBD"]) :verb)) :verb-phrase)
|
||||
((((((((["noble" "JJ"]) :adjective)) :adjectives)
|
||||
((["Caesar" "NNP"]) :noun)) :noun-phrase)) :object)) :proposition))
|
||||
) "Single adverb")
|
||||
))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue