Gold POS in Stanford parser - stanford-nlp

I’m using the Stanford parser (edu.stanford.nlp.parser.lexparser.LexicalizedParser) without gold POS-tag and in Penn style, it’s working correctly.
My test file is:
(ROOT (S (NP (NNS People)) (VP (MD can) (VP (VB butter) (NP (PRP$ their) (NN bread)) (PP (IN with) (NP (DT a) (NN knife))))) (. .)))
But when I want to use the gold POS for my test set using the -tagSeparator the train model built successfully but the test phase finished with parsing 0 sentences (without error and Ignore the test sentences).
My test file is:
People/NNS can/MD butter/VB their/PRP$ bread/NN with/IN a/DT knife/NN ./.
I read this and used this command to parse my test sentences:
java -mx1500m -cp "*" edu.stanford.nlp.parser.lexparser.LexicalizedParser -sentences newline -tokenized -tagSeparator / -tokenizerFactory edu.stanford.nlp.process.WhitespaceTokenizer -tokenizerMethod newCoreLabelTokenizerFactory -headFinder edu.stanford.nlp.trees.LeftHeadFinder -train trainpath -testTreebank testpath
Is there a separate command for this purpose (force the parser to use those tags)?
Thanks

Related

How to load an executable in Scheme using the command line

I am using DrRacket and produced a file, hello.scm in emacs with the following content:
#! /usr/bin/env racket
;The first program
(begin
(display "Hello, World!")
(newline))
I then tried to compile the file at the terminal by using le$ racket hello.scm, and received this result:
Le-MacBook-Pro:~le$ racket hello.scm
default-load-handler: expected a `module' declaration, but found
something else
file: /Users/le/hello.scm
context...:
default-load-handler
standard-module-name-resolver
module-path-index-resolve
[repeats 1 more time]
module-declared?
Moreover, when I copy and paste the content of the emacs file into DrRacket and click Run, I receive the following message:
Module Language: only a module expression is allowed, either
#lang <language-name>
or
(module <name> <language> ...)
in: (begin (display "Hello, World!") (newline))
Interactions disabled.
What exactly is the problem?
The problem was solved by adding #lang racket at the top of the emacs file.

Detecting if script executed from command line in Racket?

I'm new to Racket (and Lisp's in general) and I'm wondering if there's a canonical way to detect if a script was run from the command line?
For example, in Python the standard way to do this would be with if __name__ == __main__: as so:
def foo():
"foo!"
if __name__ == "__main__":
foo()
Now, suppose I having the following Racket code, and I'd like respond to be invoked only when this is run as a script.
#lang racket
(require racket/cmdline)
(define hello? (make-parameter #f))
(define goodbye? (make-parameter #f))
(command-line #:program "cmdtest"
#:once-each
[("-H" "--hello") "Add Hello Message" (hello? #t)]
[("-G" "--goodbye") "Add goodbye Message" (goodbye? #t)])
(define (respond)
(printf "~a\n"
(apply string-append
(cond
[(and (hello?) (goodbye?)) '("Hello" " and goodbye.")]
[(and (hello?) (not (goodbye?))) '("Hello." "")]
[(and (not (hello?)) (goodbye?)) '("" "Goodbye.")]
[else '("" "")]))))
Is there an easy/standard way to achieve what I want?
Racket has the concept of main submodules. You can read about them in the Racket Guide section entitled Main and Test Submodules. They do precisely what you want—when a file is run directly using racket or DrRacket, the main submodule is executed. If a file is used by another file using require, the main submodule is not run.
The Racket equivalent of your Python program would be the following:
#lang racket
(define (foo)
"foo!")
(module+ main
(foo))

How to run (interpret) a Scheme program stored in a file?

At the moment I am using the REPL-feature of Petite-Chez Scheme. This is working fine for small examples etc.
However, how can I store an entire program in a file ".scm", and then run (interpret) it from the command-line ? I am familiar with the (load "C:/..") command, however this only load definitions from a file into REPL.
How do I run programs using Scheme like programs in C/C++ where I compile and then execute the binary ".exe" ?
Thanks.
Briefly, you just write your program in a file, put #!/usr/bin/scheme --script as the first line of the program, mark it executable, and run it. Here's a sample script that emulates the Unix echo command:
#!/usr/bin/scheme --script
(let ([args (cdr (command-line))])
(unless (null? args)
(let-values ([(newline? args)
(if (equal? (car args) "-n")
(values #f (cdr args))
(values #t args))])
(do ([args args (cdr args)] [sep "" " "])
((null? args))
(printf "~a~a" sep (car args)))
(when newline? (newline)))))
See section 2.6 of Using Chez Scheme for details.
If you want an actual executable there are several implementations that supports compilation to native executable. Racket is one of them and it supports many different scheme versions and dialects (R5RS, R6RS, Racket, ...). There are many more. Chicken (R5RS + SRFIs), Gambit (R5RS + SRFIs) and Bigloo (R5RS, + SRFIs) to name a few.

In Chicken Scheme how can I require files when writing a script

I'm using the BDD library missbehave for Chicken Scheme to write some scripts.
I currently have a single file containing my specs and my code that I run with behave. This works as expected. Running my tests to verify the code.
I know that when using the csc compiler I can define units and link files using the following syntax
# foo.scm
(define (uses bar))
# bar.scm
(define (unit bar))
and when both files are compiled and linked this will work.
I can't find a way of acheiving something similar for a script that is run using the csi interpreter. Is there a way to do this?
An analogous concept would be require_relative in Ruby.
(load "relative_file.scm")
This works in interpreted code only. I also just found the inclub egg which looks like it works both in interpreted and compiled code.

How do you load a file into racket via command line?

I have been trying to launch a racket program from the commandline (via 'racket') but have not been having success. According to the documentation (here http://docs.racket-lang.org/reference/running-sa.html#%28part._mz-cmdline%29) passing -f followed by a file should evaluate that file. However, I can't seem to get this to work. As a test, I made the following file:
;test.rkt
#lang racket
(define a 1)
Then, running it in racket (supposedly loading the file) and attempting to recall the value of a:
racket -f test.rkt -i
Welcome to Racket v5.1.1.
> a
reference to undefined identifier: a
My end goal is to be able to launch a different program from a shell script using the --main option combined with loading the definitions with -f to start up execution, just have become a bit baffled since I can't seem to get this trivial bit working.
Removing the #lang line works, but it means that your code is no longer a module, which makes it a pretty bad idea. To start racket on a given module file, all you need is to just run racket on the file, nothing else is needed. For example, put this in test.rkt:
#lang racket/base
(printf "Hi\n")
and just run it with racket test.rkt. If you want to have command-line flags, you can use (current-command-line-arguments) to get a vector of additional command-line arguments, but there's also the racket/cmdline library that makes it much easier to have standard kinds of flag processing. Here's an example for that:
#lang racket/base
(require racket/cmdline)
(define excitedness "")
(define mode "Hi")
(command-line
#:multi
[("-e" "--excited") "add excitedness levels"
(set! excitedness (string-append excitedness "!"))]
#:once-each
[("-b" "--bye") "turn on \"bye\" mode"
(set! mode "Bye")])
(printf "~a~a\n" mode excitedness)
and you can now run it with racket test.rkt <flags>. See also the Racket Guide's section on scripts for making your test.rkt even easier to run.
Finally, there is the --main approach that you've seen -- to use that, your module needs to provide a main function that receives all the command-line flags as arguments. For example:
#lang racket/base
(require racket/string)
(provide main)
(define (main . xs)
(printf "You gave me ~s flags: ~a\n"
(length xs) (string-join xs ", ")))
and to run it:
racket -t /tmp/y -m -- foo bar baz
The flag breakdown is: -t requires your module, -m causes racket to run your main function, and -- means that the following flags are all passed to your program. You can combine the flags like so:
racket -tm- /tmp/y foo bar baz
and that would be something that you'd usually put in your script trampoline as described in that guide section.
And, of course, this is all described in great details in the reference manual.
Remove the #lang racket header from your file:
;test.rkt
(define a 1)

Resources