Commit 1d77987c authored by Jonathan Poalses's avatar Jonathan Poalses

Added example functionality to detect sample and sentence dialect methods

parent bb026b57
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
"This is an example of correct language usage. I had an idea about using garlic butter with chicken, hence the food was burnt.") "This is an example of correct language usage. I had an idea about using garlic butter with chicken, hence the food was burnt.")
(def test-sentence-two (def test-sentence-two
"This is an example of incorrect language usage, due to the word why. I had an idea about using garlic butter with chicken, hence why the food was burnt.")
(def test-sentence-three
"This is an example of incorrect language usage. I had an idea about using garlic butter with chicken, hence why the food was burnt.") "This is an example of incorrect language usage. I had an idea about using garlic butter with chicken, hence why the food was burnt.")
(def nlp (def nlp
...@@ -30,24 +33,17 @@ ...@@ -30,24 +33,17 @@
"ner"] "ner"]
:quote {:extractUnclosedQuotes "true"}})) :quote {:extractUnclosedQuotes "true"}}))
;; Take a dependency graph object and change it into a map of tokens and parts of speech labels ;; Take a sentence and figure out its dialect
(defn dependency-to-token-pos-map [graph])
;; Take a dependency graph object and change it into a map of tokens and relation labels
(defn dependency-to-token-relation-map [graph]) (defn detect-sentence-dialect [sentence]
(if (some #(= "why" %) (dl/text (dl/tokens sentence))) :bad :good))
;; Take a text sample and separate it into it's sentences, then for each sentence find its dialect, and return the most common dialect ;; Take a text sample and separate it into it's sentences, then for each sentence find its dialect, and return the most common dialect
(defn detect-sample-dialect [sample]) (defn detect-sample-dialect [sample]
(first (last (sort-by val (frequencies (map detect-sentence-dialect sample))))))
;; Take a sentence and figure out its dialect
(defn detect-sentence-dialect [sentence])
...@@ -63,6 +59,12 @@ ...@@ -63,6 +59,12 @@
(def sentences-one (def sentences-one
(dl/sentences @annotated-example-one)) (dl/sentences @annotated-example-one))
(def annotated-example-three
(delay (nlp test-sentence-three)))
(def sentences-three
(dl/sentences @annotated-example-three))
(def annotated-example-two (def annotated-example-two
(delay (nlp test-sentence-two))) (delay (nlp test-sentence-two)))
...@@ -83,8 +85,11 @@ ...@@ -83,8 +85,11 @@
(map dl/constituency-tree sentences-one) (map dl/constituency-tree sentences-one)
(map dl/constituency-tree @sentences-two) (map dl/constituency-tree @sentences-two)
(map dl/dependency-graph @sentences) (map dl/dependency-graph @sentences)
(dl/dependency-graph (nth sentences-one 1)) (datafy (dl/dependency-graph (nth sentences-one 1)))
(datafy (dl/dependency-graph (nth @sentences-two 1)))
(:leafVertices (bean (dl/dependency-graph (nth @sentences-two 1))))
(map dl/dependency-graph @sentences-two) (map dl/dependency-graph @sentences-two)
(bean (dl/dependency-graph @sentences-two))
(map dl/lemma @sentences) (map dl/lemma @sentences)
(map dl/lemma sentences-one) (map dl/lemma sentences-one)
(map dl/lemma @sentences-two) (map dl/lemma @sentences-two)
...@@ -95,6 +100,98 @@ ...@@ -95,6 +100,98 @@
(show-dependencies) (show-dependencies)
(def rats (datafy (dl/dependency-graph (nth sentences-one 1))))
(def something [5647 5858 76 938 62626])
(reduce + something)
(str 3837 345 8678)
(apply str something)
(map str something)
(def testfreq '(65 65 65 7 7 5 5 5 5 5 5 5 65 65))
(def testfreq2 '(65 65 65 7 7 5 5 2 5 5 5 5 5 65 65))
(detect-sentence-dialect sentences-one)
(detect-sentence-dialect @sentences-two)
(detect-sample-dialect sentences-one)
(detect-sample-dialect @sentences-two)
(detect-sample-dialect sentences-three)
(first (last (sort-by val (frequencies (map detect-sentence-dialect sentences-one)))))
(first (last (sort-by val (frequencies (map detect-sentence-dialect @sentences-two)))))
(first (last (sort-by val (frequencies (map detect-sentence-dialect sentences-three)))))
(detect-sentence-dialect testfreq)
(detect-sentence-dialect testfreq2)
(def testfreq '("a" "a" "a" "b" "b" "c" "c" "c" "c" "a" "a" "d" "d"))
(frequencies testfreq)
(first (last (sort-by val (frequencies testfreq))))
(detect-sentence-dialect (dl/text (dl/tokens (nth sentences-one 1))))
(detect-sentence-dialect (dl/text (dl/tokens (nth @sentences-two 1))))
(distinct testfreq)
(dedupe testfreq)
(for [someval something]
(str someval))
(doseq [someval something]
(println someval))
(last (vals rats))
(.getTarget (first (last (vals rats))))
(bean (first (last (vals rats))))
(bean (:relation (bean (first (last (vals rats))))))
(-> (vals rats)
(last)
(first)
(bean)
(:relation)
(bean))
(-> (vals rats)
(last)
(first)
(.getTarget))
*e
(System/currentTimeMillis)
(spit "test.txt" "testtesttest")
(spit "test2.txt" "{567 \"test\" 678 767}")
(slurp "test.txt")
(read-string (slurp "test2.txt"))
;; Don't use eval with arbitrary input
(def horror (eval (read-string (slurp "test2.txt"))))
horror
(dl/text sentences-one) (dl/text sentences-one)
(dl/triples sentences-one) (dl/triples sentences-one)
(dl/triples (dl/dependency-graph (nth sentences-one 1))) (dl/triples (dl/dependency-graph (nth sentences-one 1)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment