1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Natural Language Processor based on the StanfordNLP core.
17 # This tool provides a document comparison service from command line based on
18 # StanfordNLP and NLPVector consine similarity.
20 # See http://nlp.stanford.edu/software/corenlp.shtml.
27 var opt_java_cp
= new OptionString("Java classpath for StanfordNLP jars", "--cp")
28 var options
= new OptionContext
29 options
.add_option
(opt_java_cp
)
31 var arguments
= options
.rest
33 # Processor initialization
34 var java_cp
= opt_java_cp
.value
35 if java_cp
== null then java_cp
= "*"
36 var proc
= new NLPProcessor(java_cp
)
38 if arguments
.length
!= 2 then
39 print
"Usage: nitnlp text1 text2\n"
44 var doc1
= proc
.process
(arguments
.first
)
45 print doc1
.vector
.join
(":", ",")
46 var doc2
= proc
.process
(arguments
.last
)
47 print doc2
.vector
.join
(":", ",")
49 print doc1
.vector
.cosine_similarity
(doc2
.vector
)