2021-02-16 - Translations - Functions

From Izara Wiki
Jump to navigation Jump to search

Service - Translations

Lambda Functions

CreateSubjectVertex

/**
 * Create a new vertex for the subject of translations
 * @param {string} vertexId
 * @param {string} vertexLabel
 * @param {object} [vertexProperties]
 *
 * @returns {string} vertexId
 */

HdrInv

Validator: (standard)

handler logic

(standard)

logic

  1. create vertex by invoking 2021-02-16 - Graph Handler - Functions#CreateVertex
    1. vertexId: vertexId
    2. vertexLabel: vertexLabel
    3. vertexProperties: vertexProperties

CreateTranslationVertex

/**
 * Create a new vertex for a translation
 * @param {string} vertexId
 * @param {string} vertexLabel
 * @param {string} translation
 *
 * @returns {string} vertexId
 */

HdrInv

Validator: (standard)

handler logic

(standard)

logic

Create statements in graph database. Expects subject vertex to already exist (does not create subject with label/properties).

  1. create vertex by invoking 2021-02-16 - Graph Handler - Functions#CreateVertex
    1. vertexId: vertexId
    2. vertexLabel: vertexLabel
    3. vertexProperties: {translation: translation}

CreateTranslation

/**
 * Create a new translation for a source object
 * @param {string} subjectVertexId
 * @param {string} translationLabel
 * @param {string} languageCode
 * @param {string} translation
 * @param {string} userId
 *
 * @returns {Object[]} ?translation vertex id?
 */

HdrInv

Validator: (standard)

handler logic

(standard)

logic

Main job is to create statements in graph database. Expects subject vertex to already exist (will not create subject with label/properties).

  1. const translationVertexId = NPM module - izara-shared#neptuneGraphSharedLib.createVertexId
    1. vertexTag: 'translation'
    2. uniqueId: {random uuid}
  2. const existingVertices = 2021-02-16 - Graph Handler - Functions#GetDirectlyRelatedVertices to find if any existing possiblyTranslatesTo
    1. subjectId: subjectVertexId
    2. edgeLabel: possiblyTranslatesTo
  3. let hasExistingSameLanguage = false
  4. iterate existingVertices
    1. if any match this languageCode and translation can return, no additional work to be done
    2. if any match this languageCode set hasExistingSameLanguage = true
  5. create translation vertex by invoking async 2021-02-16 - Translations - Functions#CreateTranslationVertex
    1. vertexId: translationVertexId
    2. vertexLabel: translationLabel + 'Translation'
    3. translation: translation
  6. create edgeId for possiblyTranslatesTo edge:
    1. const possiblyTranslatesToEdgeId = subjectVertexId + '_Possible_' + translationLabel + '_' + languageCode + '_' + translationVertexId
  7. create possiblyTranslatesTo graph statement by invoking 2021-02-16 - Graph Handler - Functions#CreateStatement
    1. subjectId: subjectVertexId
    2. edgeLabel: 'possiblyTranslatesTo'
    3. edgeId: possiblyTranslatesToEdgeId
    4. objectId: translationVertexId
    5. edgeProperties:
      1. languageCode: languageCode
  8. if hasExistingSameLanguage == false
    1. create edgeId for translatesTo edge:
      1. const translatesToEdgeId = subjectVertexId + '_' + translationLabel + '_' + languageCode + '_' + translationVertexId
    2. create translatesTo graph statement by invoking async 2021-02-16 - Graph Handler - Functions#CreateStatement
      1. subjectId: subjectVertexId
      2. edgeLabel: 'translatesTo'
      3. edgeId: translatesToEdgeId
      4. objectId: translationVertexId
      5. edgeProperties:
        1. languageCode: languageCode
  9. if existingVertices.length == 0 (no existing possible translations)
    1. create edgeId for defaultTranslatesTo edge:
      1. const defaultTranslatesToEdgeId = subjectVertexId + '_Default_' + translationLabel + '_' + translationVertexId
    2. create defaultTranslatesTo graph statement by invoking async 2021-02-16 - Graph Handler - Functions#CreateStatement
      1. subjectId: subjectVertexId
      2. edgeLabel: 'defaultTranslatesTo'
      3. edgeId: defaultTranslatesToEdgeId
      4. objectId: translationVertexId
  10. const userVertexId = NPM module - izara-shared#neptuneGraphSharedLib.createVertexId
    1. vertexTag: 'user'
    2. uniqueId: userId
  11. create edgeId for translation createdBy edge:
    1. const createdByEdgeId = translationVertexId + '_CreatedBy_' + userVertexId
  12. create createdBy graph statement by invoking async 2021-02-16 - Graph Handler - Functions#CreateStatement
    1. subjectId: translationVertexId
    2. edgeLabel: 'createdBy'
    3. edgeId: createdByEdgeId
    4. objectId: userVertexId
    5. edgeProperties:
      1. timestamp: {current timestamp}