Coder Social home page Coder Social logo

hironsan / google-natural-language-sampler Goto Github PK

View Code? Open in Web Editor NEW
13.0 4.0 6.0 13 KB

Code examples for Google Natural Language API.

License: MIT License

natural-language-processing python gcp sentiment-analysis named-entity-recognition syntax-analysis text-classification entity-sentiment-analysis

google-natural-language-sampler's Introduction

google-natural-language-sampler

Code examples for Google Natural Language API written in Python.

Description

Example codes has following features:

  • Sentiment Analysis
  • Named Entity Recognition
  • Syntax Analysis
  • Entity Sentiment Analysis
  • Text Classification
  • Text Annotation

Requirement

  • Python 3.x
  • Credentials

Setup

To install necessary library, simply use pip:

pip install google-cloud-language

or,

pip install -r requirements.txt

Next, set up to authenticate with the Cloud Natural Language API using your project's service account credentials. Then, set the GOOGLE_APPLICATION_CREDENTIALS environment variable to point to your downloaded service account credentials:

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/credentials-key.json

Quick Start: Running the Example

Sentiment Analysis

$ python examples/sentiment_analysis.py "President Obama looks very happy."
    Sentiment score: 0.4000000059604645
Sentiment magnitude: 0.4000000059604645

For more information, see Analyzing sentiment.

Named Entity Recognition

$ python examples/named_entities.py "President Obama is speaking at the White House."
====================
         name: Obama
         type: PERSON
     salience: 0.9082207679748535
wikipedia_url: -
====================
         name: White House
         type: LOCATION
     salience: 0.09177924692630768
wikipedia_url: https://en.wikipedia.org/wiki/White_House

For more information, see Analyzing entities.

Syntax Analysis

$ python examples/syntax_analysis.py "President Obama is speaking at the White House."
NOUN: President
NOUN: Obama
VERB: is
VERB: speaking
ADP: at
DET: the
NOUN: White
NOUN: House
PUNCT: .

For more information, see Analyzing syntax.

Entity Sentiment Analysis

$ python examples/entity_sentiment.py "President Obama is speaking at the White House."
====================
         name: Obama
         type: PERSON
     salience: 0.9082207679748535
wikipedia_url: -
    magnitude: 0.10000000149011612
        score: 0.0
====================
         name: White House
         type: LOCATION
     salience: 0.09177924692630768
wikipedia_url: https://en.wikipedia.org/wiki/White_House
    magnitude: 0.0
        score: 0.0

For more information, see Analyzing entity sentiment.

Text Classification

$ python examples/classify_text.py "On Saturday, Sevilla FC announced the signing of Spanish defender Aleix Vidal from defending LaLiga champions FC Barcelona. Via their official website, Barcelona said they were to receive €8.5 million transfer as well as two million in variables."
====================
name            : /Sports/Team Sports/Soccer
confidence      : 0.9900000095367432
====================
name            : /News
confidence      : 0.550000011920929

For more information, see Classifying text. In the content category page, You can see all categories returned by classify_text method.

Text Annotation

$ python examples/annotate_text.py "President Obama looks very happy."
    Sentiment score: 0.4000000059604645
Sentiment magnitude: 0.4000000059604645
====================
         name: Obama
         type: PERSON
     salience: 1.0
wikipedia_url: https://en.wikipedia.org/wiki/Barack_Obama

For more information, see AnnotateTextRequest.

Licence

MIT

Author

Hironsan

References

google-natural-language-sampler's People

Contributors

hironsan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

google-natural-language-sampler's Issues

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.

Traceback (most recent call last):
  File "/python/google-natural-language-sampler/examples/sentiment_analysis.py", line 4, in <module>
    from google.cloud.language import enums
ImportError: cannot import name 'enums' from 'google.cloud.language' (/home/praharsh/.local/lib/python3.9/site-packages/google/cloud/language/__init__.py)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.