Skip to content

Latest commit

 

History

History

4.LogicApp

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

4. Real-time scoring

Create logic to get real-time prediction

4.1 Logic overview

This logic app consist with three parts Recurrence, Search tweets and For each modules.

The last For each module consist with multiple modules.

4.1.1 Recurrence

  • Add Recurrence module and configure it like following

4.1.2 Search Tweets

  • Add Twitter Search and type key word to search

4.1.3 For each

  • Add For each module as the next action
  • Select Twitter body

4.1.3.1 For each > Condition

  • Add Condition action fron Control module

  • Select TweetLanguageCode for the condition and type en for the value

4.1.3.2 For each > Condition > True

Click 'Add an action' inside True

We will leave False empty

4.1.3.3 For each > Condition > Ture > Parse JSON

parameter name value
content @{items('For_each')}

Copy following json schema

{
    "properties": {
        "CreatedAt": {
            "type": "string"
        },
        "CreatedAtIso": {
            "type": "string"
        },
        "Favorited": {
            "type": "boolean"
        },
        "MediaUrls": {
            "type": "array"
        },
        "OriginalTweet": {},
        "RetweetCount": {
            "type": "integer"
        },
        "TweetId": {
            "type": "string"
        },
        "TweetInReplyToUserId": {
            "type": "string"
        },
        "TweetLanguageCode": {
            "type": "string"
        },
        "TweetText": {
            "type": "string"
        },
        "TweetedBy": {
            "type": "string"
        },
        "UserDetails": {},
        "UserMentions": {}
    },
    "type": "object"
}

4.1.3.4 For each > Condition > Ture > Compose

Copy next JSON text to Input parameter

[
  {
    "id": "@{body('Parse_JSON')?['TweetId']}",
    "text": "@{replace(string(body('Parse_JSON')?['TweetText']), '\"', '')}"
  }
]

4.1.3.5 For each > Condition > Ture > HTTP

Add HTTP module

parameter name value
Method POST
URI Copy from Azure Databricks Notebook 4, cell 34th, scoring_uri
Headers Authorization
Headers Content-Type
Headers-Authorization Bearer Copy from Azure Databricks Notebook 4, cell 34th, api_key
Headers-Content-Type application/json
Body @base64(outputs('Compose'))

4.1.3.6 For each > Condition > Ture > Parse JSON 2

  • Add Parse JSON module
parameter name value
content json(body('HTTP'))
{
    "items": {
        "type": "string"
    },
    "type": "array"
}

4.1.3.7 For each > Condition > Ture > For each 2

  • Add For each module
@body('Parse_JSON_2')

4.1.3.8 For each > Condition > Ture > For each 2 > Parse JSON 3

  • Add Parse JSON module
parameter name value
content @{items('For_each')}
  • And then copy and pate following JSON schema to logic app
{
    "properties": {
        "id": {
            "type": "string"
        },
        "prediction": {
            "maximum": 1,
            "minimum": 0,
            "type": "number"
        },
        "text": {
            "type": "string"
        }
    },
    "type": "object"
}

4.1.3.9 For each > Condition > Ture > For each 2 > Compose 2

  • Add Compose module and, copy and paste following JSON to the module
{
  "body": @{items('For_each')},
  "id": @{guid()},
  "prediction": @{float(body('Parse_JSON_3')?['prediction'])},
  "tweetid": "@{body('Parse_JSON_3')?['id']}"
}

4.1.3.10 For each > Condition > Ture > For each 2 > Parse JSON 4

  • Add Parse JSON module and, copy and past following JSON to the module
{
    "properties": {
        "body": {
            "properties": {},
            "type": "object"
        },
        "id": {
            "type": "string"
        },
        "prediction": {
            "type": "number"
        },
        "tweetid": {
            "type": "string"
        }
    },
    "type": "object"
}

4.1.3.11 For each > Condition > Ture > For each 2 > Create or Update document

  • Add Create or Update document from CosmosDB module

  • Add Parition Key value parameter
parameter name value
Database ID socialmedia
Collection ID twitter
Document @{outputs('Compose_2')}
Parition key value "@{body('Parse_JSON_4')?['id']}"