Giter Club home page Giter Club logo

gsoc-2018's Introduction

fluid-adaptive-content-service

Repo for GSOC Project Described at https://wiki.fluidproject.org/display/fluid/Google+Summer+of+Code+2018+with+the+Fluid+Project#GoogleSummerofCode2018withtheFluidProject-Buildaserviceforadaptivecontentandlearningsupports

Table of Contents

Instructions to run the service locally

Step 1 - Clone the Repository

Step 2 - Install the required node modules

Run

npm install

Step 3 - Setting API keys for services that require it

Third-party services that require API key -

You can visit their respective websites and acquire their API keys to use the service.
After acquiring the API keys, you will have to add them to the environment variables by creating a .env file.
You can refer to the .env.example file in this repository to know how your .env file should look like.

Step 4 - Start the service server

  • All Services together
npm start

This will run all the endpoints, from all the services, at port 8080

  • Dictionary Service Server
npm run dictionary

This will run all the dictionary service server, at port 8081

  • NLP Service Server
npm run nlp

This will run all the nlp service server, at port 8082

  • Translation Service Server
npm run translation

This will run all the translation service server, at port 8083

Note that all the above commands should be run at the root of the repository

When the server starts, it is ready to accept requests at the available endpoints.

Available Endpoints

Currently available endpoints -

Dictionary Service

  • General Endpoints

    • http://localhost:8081/v1/dictionary/{language_code}/definition/{word}
      Method: GET
      Language Code: English (en), French (fr) and German (de)

    • http://localhost:8081/v1/dictionary/{language_code}/synonyms/{word}
      Method: GET
      Language Code: IANA standards

    • http://localhost:8081/v1/dictionary/{language_code}/antonyms/{word}
      Method: GET
      Language Code: IANA standards

    • http://localhost:8081/v1/dictionary/{language_code}/pronunciations/{word}
      Method: GET
      Language Code: IANA standards

    • http://localhost:8081/v1/dictionary/{language_code}/frequency/{word}
      Method: GET
      Language Code: IANA standards

    • http://localhost:8081/v1/dictionary/{language_code}/frequency/{word}/{lexicalCategory}
      Method: GET
      Language Code: IANA standards

    • http://localhost:8081/v1/dictionary/langs/{endpoint_name}
      Method: GET

    Example endpoints:

    • http://localhost:8081/v1/dictionary/fr/definition/rien
    • http://localhost:8081/v1/dictionary/langs/definition
  • Wiktionary Endpoints

    • http://localhost:8081/v1/dictionary/wiktionary/{language_code}/definition/{word}
      Method: GET
      Language Code: English (en), French (fr) and German (de)

    • http://localhost:8081/v1/dictionary/wiktionary/languages
      Method: GET

    • http://localhost:8081/v1/dictionary/wiktionary/langs/{endpoint_name}
      Method: GET

    Example endpoints:

    • http://localhost:8081/v1/dictionary/wiktionary/fr/definition/rien
    • http://localhost:8081/v1/dictionary/wiktionary/languages
    • http://localhost:8081/v1/dictionary/wiktionary/langs/definition
  • Oxford Endpoints

    • http://localhost:8081/v1/dictionary/oxford/{language_code}/definition/{word}
      Method: GET
      Language Code: IANA standards

    • http://localhost:8081/v1/dictionary/oxford/{language_code}/synonyms/{word}
      Method: GET
      Language Code: IANA standards

    • http://localhost:8081/v1/dictionary/oxford/{language_code}/antonyms/{word}
      Method: GET
      Language Code: IANA standards

    • http://localhost:8081/v1/dictionary/oxford/{language_code}/pronunciations/{word}
      Method: GET
      Language Code: IANA standards

    • http://localhost:8081/v1/dictionary/oxford/{language_code}/frequency/{word}
      Method: GET
      Language Code: IANA standards

    • http://localhost:8081/v1/dictionary/oxford/{language_code}/frequency/{word}/{lexicalCategory}
      Method: GET
      Language Code: IANA standards

    • http://localhost:8081/v1/dictionary/oxford/languages
      Method: GET

    • http://localhost:8081/v1/dictionary/oxford/langs/{endpoint_name}
      Method: GET

Example endpoints:

  • http://localhost:8081/v1/dictionary/oxford/en/definition/horse
  • http://localhost:8081/v1/dictionary/oxford/languages
  • http://localhost:8081/v1/dictionary/oxford/langs/definition

NLP Service

  • Compromise

    • http://localhost:8082/v1/nlp/compromise/tags
      Method: POST
      Request Body Format: { sentence: "{sentence to be tagged}" }

Example endpoints:

  • http://localhost:8082/v1/nlp/compromise/tags
    Body { sentence: "Hello world! This is a test sentence" }

Translation Service

  • General

    • http://localhost:8083/v1/translation/translate/{source_lang}-{target_lang}
      Method: POST
      Request Body Format: { text: "text to be translated"}
      Language Code: ISO 639-1 (2-lettered language codes)

    • http://localhost:8083/v1/translation/detect
      Method: POST
      Request Body Format: { text: "text for which language is to be detected"}
      Language Code: ISO 639-1 (2-lettered language codes), ISO 639-2 (3-lettered language code)

    • http://localhost:8083/v1/translation/translate/{target_lang}
      Method: POST
      Request Body Format: { text: "text to be translated"}
      Language Code: ISO 639-1 (2-lettered language codes)

    • http://localhost:8083/v1/translation/langs/translate
      Method: GET

    Example endpoints:

    • http://localhost:8083/v1/translation/translate/en-de
      Body { text: "This is the text to be translated" }
    • http://localhost:8083/v1/translation/detect
      Body { text: "This is the text for which the language is to be detected" }
    • http://localhost:8083/v1/translation/translate/de
      Body { text: "This is the text to be translated" }
    • http://localhost:8083/v1/translation/languages\
  • Yandex

    • http://localhost:8083/v1/translation/yandex/translate/{source_lang}-{target_lang}
      Method: POST
      Request Body Format: { text: "text to be translated"}
      Language Code: ISO 639-1 (2-lettered language codes)

    • http://localhost:8083/v1/translation/yandex/detect
      Method: POST
      Request Body Format: { text: "text for which language is to be detected"}
      Language Code: ISO 639-1 (2-lettered language codes)

    • http://localhost:8083/v1/translation/yandex/translate/{target_lang}
      Method: POST
      Request Body Format: { text: "text to be translated"}
      Language Code: ISO 639-1 (2-lettered language codes)

    • http://localhost:8083/v1/translation/yandex/languages
      Method: GET

    • http://localhost:8083/v1/translation/yandex/langs/translate
      Method: GET

    Example endpoints:

    • http://localhost:8083/v1/translation/yandex/translate/en-de
      Body { text: "This is the text to be translated" }
    • http://localhost:8083/v1/translation/yandex/detect
      Body { text: "This is the text for which the language is to be detected" }
    • http://localhost:8083/v1/translation/yandex/translate/de
      Body { text: "This is the text to be translated" }
    • http://localhost:8083/v1/translation/yandex/languages\
  • Google

    • http://localhost:8083/v1/translation/google/translate/{target_lang}
      Method: POST
      Request Body Format: { text: "text to be translated"}
      Language Code: ISO 639-1 (2-lettered language codes), ISO 639-2 (3-lettered language code)

    • http://localhost:8083/v1/translation/google/detect
      Method: POST
      Request Body Format: { text: "text for which language is to be detected"}
      Language Code: ISO 639-1 (2-lettered language codes), ISO 639-2 (3-lettered language code)

    • http://localhost:8083/v1/translation/google/languages
      Method: GET

    • http://localhost:8083/v1/translation/google/languages/{lang}
      Method: GET
      Language Code: ISO 639-1 (2-lettered language codes), ISO 639-2 (3-lettered language code)

    • http://localhost:8083/v1/translation/google/langs/translate
      Method: GET

    Example endpoints:

    • http://localhost:8083/v1/translation/google/translate/en
      Body { text: "This is the text to be translated" }
    • http://localhost:8083/v1/translation/google/detect
      Body { text: "This is the text for which the language is to be detected" }
    • http://localhost:8083/v1/translation/google/languages\
    • http://localhost:8083/v1/translation/google/languages/fr\

Running Tests

Tests for these endpoints lie in -

  • share/dictionary/tests/ - Tests for dictionary endpoints
  • share/nlp/tests/ - Tests for nlp endpoints
  • share/translation/tests/ - Tests for translation endpoints

There are 3 kinds of tests for each service -

  • Unit Tests - Tests for individual functions
  • Integration Tests - Testing the overall functioning of the endpoint (using mock test servers)
  • Contract Tests - Testing if the external service provides data with the expected structure

There are several ways of running the tests -

  • Running all Unit and Integration tests of all services togther
npm test
  • Running all Contract tests of all services together
npm run test-contract
  • Running all Unit and Integration tests of a particular service
// for dictionary service
npm run test-dictionary

// for nlp service
npm run test-nlp

// for translation service
npm run test-translation
  • Running all Contract tests of a particular service
// for dictionary service
npm run test-dictionary-contract

// for nlp service
npm run test-nlp-contract

// for translation service
npm run test-translation-contract
  • To run a particular test
node /relative/path/to/the/test/file

Note that all the above commands for running tests should be run at the root of the repository

Documentation

Learn more about the service and the endpoints, in its documentation, which can be found here.

Notes for use of third-party services

The API serves as a useful wrapper around several third-party services -

Make sure you read their Terms of Conditions and their Branding Requirements for the use of the service they provide.

Oxford

Wiktionary

Yandex

Google

gsoc-2018's People

Contributors

kunal-mohta avatar waharnum avatar

Watchers

James Cloos avatar

Forkers

waharnum

gsoc-2018's Issues

Improve AJV Schema errors for Contract tests

AJV gives very ambiguous error messages like the following

'data[0].name' SHOULD be of the type NUMBER
'data[1].name' SHOULD be of the type NUMBER

It would be nice to make it possible for the error message to have a proper replacement for data in the error log message.

Integration tests for "authentication failed" cases

As the authentication keys are passed from the environment variable to the required grades and then used, it is difficult to test the authentication failed responses.
If we wanted to change the grade options/configurations for all the cases of the integration test of an endpoint, then it could have been done by overriding the actual request grade with a test grade (like the service does to override character limit for testing purposes).
But this is not the case here. For this, we need to change the grade only for a particular case of the integration tests.

Possible solution(s)

  • Have a separate grade for testing the authentication failed cases, i.e. essentially separate tests. This would require figuring out a way to let the mock servers know that it has to send an authentication failed response, based on the authentication key used.
  • As we are using mock servers with nock, we can trigger the authentication failed response by having a particular mark on the request we send.
    For example, if the endpoint accepts a post data, then we can have a particular predefined data that will trigger the authentication failed response.

Google Translation - Handle language codes with greater than 3 letters

All the services involving language codes, have codes with number of letters less than or equal to 3. However Google has two language whose code has number of letters greater than 3.

Language - Chinese (Simplified)
Code - zh-CN

Language - Chinese (Traditional)
Code - zh-TW

How to handle these separatly is yet to be figured.

Unexpected error message at the end of Contract Tests, when API keys absent

I implemented a prompt and termination of Contract tests when API key(s) that are required are not present in the .env file.
This seems to work properly when running a single Contract test, but gives an unexpected npm error log at the end, when running multiple tests together, and all of them terminate due to absence of API keys.
Here is a screenshot of the error log -
gsoc

Steps to reproduce

  • Remove the Yandex and Google API keys from the .env file
  • Run npm run test-translation-contract

Speculated reason for the error

I am checking for the API keys before registering the tests. So when the the keys are absent, no test is run, which leads to an unexpected end of the node file.

Note that the error occurs only when running multiple tests and ALL of them fail. If, for example, you were to remove Yandex keys from .env but keep Google ones, then there would be no error when running all translation contract tests.

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.