Elixir wrapper for Google Cloud Natural Language API. See Cloud Natural Language API
Latest version 0.2.2 doc.
The package can be installed as:
- Add
gc_nlp
to your list of dependencies inmix.exs
:
```elixir
def deps do
[{:gc_nlp, "~> 0.2.2"}]
end
```
- Ensure
gc_nlp
is started before your application:
```elixir
def application do
[applications: [:gc_nlp]]
end
```
- Put your Google Cloud credential json file in 'config/' or modify the appropriate Goth config. Refer to this guide to get your credential file. Default to expect "gcloud-secret.json" inside config directory.
-
Sentiment Analysis
iex> GcNLP.analyze_sentiment "There is a lot of new features coming in Elixir 1.4" %{"documentSentiment" => %{"magnitude" => 0.1, "polarity" => 1}, "language" => "en"}
-
Entity Analysis
iex> GcNLP.analyze_entities "There is a lot of new features coming in Elixir 1.4" %{"entities" => [%{"mentions" => [%{"text" => %{"beginOffset" => 41, "content" => "Elixir 1.4"}}], "metadata" => %{}, "name" => "Elixir 1.4", "salience" => 0.16144496, "type" => "OTHER"}], "language" => "en"}
-
Syntactic Analysis
iex> GcNLP.annotate_text "There is a lot of new features coming in Elixir 1.4" %{"documentSentiment" => %{"magnitude" => 0.1, "polarity" => 1}, "entities" => [%{"mentions" => [%{"text" => %{"beginOffset" => 41, "content" => "Elixir 1.4"}}], "metadata" => %{}, "name" => "Elixir 1.4", "salience" => 0.16144496, "type" => "OTHER"}], "language" => "en", "sentences" => [%{"text" => %{"beginOffset" => 0, "content" => "There is a lot of new features coming in Elixir 1.4"}}], "tokens" => [%{"dependencyEdge" => %{"headTokenIndex" => 1, "label" => "EXPL"}, "lemma" => "There", "partOfSpeech" => %{"tag" => "DET"}, "text" => %{"beginOffset" => 0, "content" => "There"}}, %{"dependencyEdge" => %{"headTokenIndex" => 1, "label" => "ROOT"}, "lemma" => "be", "partOfSpeech" => %{"tag" => "VERB"}, "text" => %{"beginOffset" => 6, "content" => "is"}}, ...}