CoreNLP v0.1.0 CoreNLP

This module provides a thin client interface into a Stanford CoreNLP server.

Summary

Functions

Annotate provided text with all available annotators

Annotate provided text with specific processing properties set

A test to let the caller know if the server is alive, but not necessarily ready to respond to requests

A simple ping test. Responds with pong if the server is up

A test to let the caller know if the server is alive AND ready to respond to requests

Applies a Semgrex pattern to the provided text

Applies a TokensRegex pattern to the provided text

Applies a Tregex pattern to the provided text

Functions

annotate(text)
annotate(text :: binary) :: tuple

Annotate provided text with all available annotators.

Unless you have a server tuned to handle this level of processing, it is strongly recommended to use CoreNLP.annotate/2 to scope the level of processing applied to the provided text.

annotate(text, properties)
annotate(text :: binary, properties :: keyword) :: tuple
annotate(text :: binary, properties :: map) :: tuple

Annotate provided text with specific processing properties set.

See the official Stanford CoreNLP documentation for available options.

Examples

iex> CoreNLP.annotate("The cat sat.", annotators: "tokenize,ssplit,pos")
{:ok,
 %{"sentences" => [%{"index" => 0,
      "tokens" => [%{"after" => " ", "before" => "",
         "characterOffsetBegin" => 0, "characterOffsetEnd" => 3, "index" => 1,
         "originalText" => "The", "pos" => "DT", "word" => "The"},
       %{"after" => " ", "before" => " ", "characterOffsetBegin" => 4,
         "characterOffsetEnd" => 7, "index" => 2, "originalText" => "cat",
         "pos" => "NN", "word" => "cat"},
       %{"after" => "", "before" => " ", "characterOffsetBegin" => 8,
         "characterOffsetEnd" => 11, "index" => 3, "originalText" => "sat",
         "pos" => "VBD", "word" => "sat"},
       %{"after" => "", "before" => "", "characterOffsetBegin" => 11,
         "characterOffsetEnd" => 12, "index" => 4, "originalText" => ".",
         "pos" => ".", "word" => "."}]}]}}
live()

A test to let the caller know if the server is alive, but not necessarily ready to respond to requests.

Examples

iex(2)> CoreNLP.live()
{:ok, "live"}
ping()

A simple ping test. Responds with pong if the server is up.

Examples

iex> CoreNLP.ping()
{:ok, "pong"}
ready()

A test to let the caller know if the server is alive AND ready to respond to requests.

Examples

iex(3)> CoreNLP.ready()
{:ok, "ready"}
semgrex(text, pattern, filter \\ false)
semgrex(text :: binary, pattern :: binary, filter :: boolean) :: tuple

Applies a Semgrex pattern to the provided text.

See the official Stanford Semgrex documentation for more information.

Examples

iex> CoreNLP.semgrex("The quick brown fox jumped over the lazy dog.", ~S|{pos:/VB.*/} >nsubj {}=subject >/nmod:.*/ {}=prep_phrase|)
{:ok,
 %{"sentences" => [%{"0" => %{"$prep_phrase" => %{"begin" => 8, "end" => 9,
          "text" => "dog"},
        "$subject" => %{"begin" => 3, "end" => 4, "text" => "fox"},
        "begin" => 4, "end" => 5, "text" => "jumped"}, "length" => 1}]}}
tokensregex(text, pattern, filter \\ false)
tokensregex(text :: binary, pattern :: binary, filter :: boolean) :: tuple

Applies a TokensRegex pattern to the provided text.

See the official Stanford TokensRegex documentation for more information.

Examples

iex> CoreNLP.tokensregex("The quick brown fox jumps over the lazy dog.", ~S/(?$foxtype [{pos:JJ}]+ ) fox/)
{:ok,
 %{"sentences" => [%{"0" => %{"$foxtype" => %{"begin" => 1, "end" => 3,
          "text" => "quick brown"}, "begin" => 1, "end" => 4,
        "text" => "quick brown fox"}, "length" => 1}]}}
tregex(text, pattern)
tregex(text :: binary, pattern :: binary) :: tuple

Applies a Tregex pattern to the provided text.

See the official Stanford Tregex documentation for more information.

Examples

iex> CoreNLP.tregex("The quick brown fox jumped over the lazy dog.", "NP < NN=animal")
{:ok,
 %{"sentences" => [%{"0" => %{"match" => "(NP (DT The) (JJ quick) (JJ brown) (NN fox))\n",
        "namedNodes" => [%{"animal" => "(NN fox)\n"}]},
      "1" => %{"match" => "(NP (DT the) (JJ lazy) (NN dog))\n",
        "namedNodes" => [%{"animal" => "(NN dog)\n"}]}}]}}