From 3f36771267831a53e07a89297d37261d48dbecb6 Mon Sep 17 00:00:00 2001 From: Aravind V Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 14 Mar 2021 22:36:03 +0530 Subject: [PATCH] Add comparison scripts Signed-off-by: Aravind V Nair <22199259+aravindvnair99@users.noreply.github.com> --- script_comparison/a.js | 36 ++++++++++++++++++++++++++++++++++++ script_comparison/a.py | 15 +++++++++++++++ script_comparison/a.sh | 8 ++++++++ script_comparison/run.sh | 6 ++++++ 4 files changed, 65 insertions(+) create mode 100644 script_comparison/a.js create mode 100644 script_comparison/a.py create mode 100644 script_comparison/a.sh create mode 100644 script_comparison/run.sh diff --git a/script_comparison/a.js b/script_comparison/a.js new file mode 100644 index 0000000..8224bea --- /dev/null +++ b/script_comparison/a.js @@ -0,0 +1,36 @@ +const https = require("https"); + +const data = JSON.stringify({ + document: { + text: + "Michael Jordan was one of the best basketball players of all time. Scoring was Jordan stand-out skill, but he still holds a defensive NBA record, with eight steals in a half.", + }, +}); + +const options = { + hostname: "nlapi.expert.ai", + port: 443, + path: "/v2/analyze/standard/en/entities", + method: "POST", + headers: { + "Content-Type": "application/json; charset=utf-8", + "Content-Length": data.length, + "Authorization": + "Bearer eyJraWQiOiI1RDVOdFM1UHJBajVlSlVOK1RraXVEZE15WWVMMFJQZ3RaUDJGTlhESHpzPSIsImFsZyI6IlJTMjU2In0.eyJjdXN0b206Y291bnRyeSI6IklOIiwic3ViIjoiNzY0MmZiYTMtOTdiYy00ODM2LTkyMzQtNmZmODBkY2MxMmEzIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImN1c3RvbTpwZXJzb25hbGl6YXRpb25BdXRoIjoiMSIsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC5ldS13ZXN0LTEuYW1hem9uYXdzLmNvbVwvZXUtd2VzdC0xX0FVSGdRMDhDQiIsImNvZ25pdG86dXNlcm5hbWUiOiI3NjQyZmJhMy05N2JjLTQ4MzYtOTIzNC02ZmY4MGRjYzEyYTMiLCJjdXN0b206Y29tcGFueSI6IlN0dWRlbnQiLCJhdWQiOiI1a2g5YzBtb2NuajkyM3FkY2pzazM3OHN2aCIsImV2ZW50X2lkIjoiOTI4Y2FiZWEtNjdlZS00YTlmLWFjMGUtZDFkY2VjYmJjNWMwIiwidG9rZW5fdXNlIjoiaWQiLCJhdXRoX3RpbWUiOjE2MTQ0NTM0OTgsIm5hbWUiOiJTcmkiLCJleHAiOjE2MTQ1Mzk4OTgsImlhdCI6MTYxNDQ1MzQ5OCwiZmFtaWx5X25hbWUiOiJOdXRoZXRpIiwiZW1haWwiOiJudXRoZXRpLmxhYXN5YUBnbWFpbC5jb20iLCJjdXN0b206bWFya2V0aW5nQXV0aCI6IjEifQ.VxzURWbl0xfwYPYBSLqjJQFhegxpeCUaCk1VXL4ehjred_RPfwB7tyJW_9jqotowEEiAcaakUbdx3VvIIAKC0KAz-nj-xpVfiKOQwN-fEfriMjBdWSUGkRtXUGqIzgdYThrOR_hH3dcTw3EiRTqim2lTu0LahQuT0G52J_X19resixA2o6YyqQ2kiu8cQtqIiyJ3cyisVyRMiYkUw6tzgq__Or6Oalb7eR1KgtyKTaOlXLzd5eW_1sL49bW9yQvnCA8VVNZTXvg4gj4vaG-sFHrYpnmo3MO1zoybLpcoA6-GFxxIrvO49xSnG5re1ASnmTd3kZDTqZB3OtkOs-3N4w", + }, +}; + +const req = https.request(options, (res) => { + console.log(`statusCode: ${res.statusCode}`); + + res.on("data", (d) => { + process.stdout.write(d); + }); +}); + +req.on("error", (error) => { + console.error(error); +}); + +req.write(data); +req.end(); diff --git a/script_comparison/a.py b/script_comparison/a.py new file mode 100644 index 0000000..84e512e --- /dev/null +++ b/script_comparison/a.py @@ -0,0 +1,15 @@ +from dotenv import load_dotenv +from expertai.nlapi.cloud.client import ExpertAiClient +load_dotenv() +client = ExpertAiClient() + +text = "Michael Jordan was one of the best basketball players of all time. Scoring was Jordan's stand-out skill, but he still holds a defensive NBA record, with eight steals in a half." +language= 'en' + +output = client.specific_resource_analysis(body={"document": {"text": text}}, params={'language': language, 'resource': 'entities'}) + +print (f'{"ENTITY":{50}} {"TYPE":{10}}') +print (f'{"------":{50}} {"----":{10}}') + +for entity in output.entities: + print (f'{entity.lemma:{50}} {entity.type_:{10}}') diff --git a/script_comparison/a.sh b/script_comparison/a.sh new file mode 100644 index 0000000..60cbb66 --- /dev/null +++ b/script_comparison/a.sh @@ -0,0 +1,8 @@ +curl -X POST https://nlapi.expert.ai/v2/analyze/standard/en/entities \ + -H 'Authorization: Bearer eyJraWQiOiI1RDVOdFM1UHJBajVlSlVOK1RraXVEZE15WWVMMFJQZ3RaUDJGTlhESHpzPSIsImFsZyI6IlJTMjU2In0.eyJjdXN0b206Y291bnRyeSI6IklOIiwic3ViIjoiNzY0MmZiYTMtOTdiYy00ODM2LTkyMzQtNmZmODBkY2MxMmEzIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImN1c3RvbTpwZXJzb25hbGl6YXRpb25BdXRoIjoiMSIsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC5ldS13ZXN0LTEuYW1hem9uYXdzLmNvbVwvZXUtd2VzdC0xX0FVSGdRMDhDQiIsImNvZ25pdG86dXNlcm5hbWUiOiI3NjQyZmJhMy05N2JjLTQ4MzYtOTIzNC02ZmY4MGRjYzEyYTMiLCJjdXN0b206Y29tcGFueSI6IlN0dWRlbnQiLCJhdWQiOiI1a2g5YzBtb2NuajkyM3FkY2pzazM3OHN2aCIsImV2ZW50X2lkIjoiOTI4Y2FiZWEtNjdlZS00YTlmLWFjMGUtZDFkY2VjYmJjNWMwIiwidG9rZW5fdXNlIjoiaWQiLCJhdXRoX3RpbWUiOjE2MTQ0NTM0OTgsIm5hbWUiOiJTcmkiLCJleHAiOjE2MTQ1Mzk4OTgsImlhdCI6MTYxNDQ1MzQ5OCwiZmFtaWx5X25hbWUiOiJOdXRoZXRpIiwiZW1haWwiOiJudXRoZXRpLmxhYXN5YUBnbWFpbC5jb20iLCJjdXN0b206bWFya2V0aW5nQXV0aCI6IjEifQ.VxzURWbl0xfwYPYBSLqjJQFhegxpeCUaCk1VXL4ehjred_RPfwB7tyJW_9jqotowEEiAcaakUbdx3VvIIAKC0KAz-nj-xpVfiKOQwN-fEfriMjBdWSUGkRtXUGqIzgdYThrOR_hH3dcTw3EiRTqim2lTu0LahQuT0G52J_X19resixA2o6YyqQ2kiu8cQtqIiyJ3cyisVyRMiYkUw6tzgq__Or6Oalb7eR1KgtyKTaOlXLzd5eW_1sL49bW9yQvnCA8VVNZTXvg4gj4vaG-sFHrYpnmo3MO1zoybLpcoA6-GFxxIrvO49xSnG5re1ASnmTd3kZDTqZB3OtkOs-3N4w' \ + -H 'Content-Type: application/json; charset=utf-8' \ + -d '{ + "document": { + "text" : "Michael Jordan was one of the best basketball players of all time. Scoring was Jordan stand-out skill, but he still holds a defensive NBA record, with eight steals in a half." + } +}' diff --git a/script_comparison/run.sh b/script_comparison/run.sh new file mode 100644 index 0000000..e03c3fe --- /dev/null +++ b/script_comparison/run.sh @@ -0,0 +1,6 @@ +printf "\nRunning Shell Script" +time for run in {1..10}; do sh ./a.sh > /dev/null; done +printf "\nRunning JavaScript" +time for run in {1..10}; do node a.js > /dev/null; done +printf "\nRunning Python Script" +time for run in {1..10}; do py a.py > /dev/null; done