Basic JSON - issue with the bloody bracket - node.js

For a while now I've been trying to add Airtouch to HOmebridge and failing miserably.
Current attempt
The original code is this
"platforms": [
{
"platform": "Airtouch",
"name": "Airtouch",
"ip_address": "192.168.0.10",
"ac_include_temps": false,
"units": [
{
"manufacturer": "LG",
"model": "B36AWY-7G6",
"fan": ["AUTO", "QUIET", "LOW", "MEDIUM"]
}
]
}
]
What am I missing? Happy to find someone to be able to troubleshoot & fix :)
Validation error:
Validation error

Thank you all, #user1239299 for sticking around, and #alexanderdavide for sharing the validator tool
I believe I figured out what the error was
I would love to know how to make it perfectly line up though:
enter image description here
At the moment it looks ugly. And when I move the lines of code to match the first picture, and upon saving the config, I get this. The last two brackets caused the issue :) :
enter image description here

The square brackets do align with each other

Related

IBM Cloud Functions printing API response in Watson Assistant / node.js / json

With IBM cloud functions I am calling two Joke APIs. The first one gives me these results:
Results:
{
"response": {
"body": {
"body": [
{
"_id": "5f80ccd641785ba7c7d27bc0",
"punchline": "They always egg-cercise!",
"setup": "How do hens stay fit?",
"type": "general"
}
],
"success": true
},
I want to print the punchline and setup in Watson assistant so I tried this code:
$webhook_result_1.response.body.body.setup and $webhook_result_1.response.body.body.punchline but both gives me an error. When I use $webhook_result_1.response.body.body I get this:
[{"_id":"5f80ccd641785ba7c7d27c07","punchline":"A JOKE MACHINE!?","setup":"What do I look like?","type":"general"}]
So I guess I am on the right way. What am I doing wrong?
—
This is the response for the second joke API:
Results:
{
"response": [
{
"id": 299,
"punchline": "The meat-ball.",
"setup": "Where do hamburgers go to dance?",
"type": "general"
}
]
}
And I tried this: $webhook_result_2.response.punchline but it is not working as well.
How can I print the punchline and setup for each API?
The [] indicates an array, so you need to index it. Ideally you should check an array to see that it has at least one element, and then iterate through it, but your 1st element, if it exists, will be:
$webhook_result_1.response.body.body[0].setup
Based on the comments to your question, it appears that you are placing the opening bracket in the wrong place.

What is a GitLab line_code as referenced when creating a new merge request thread

I'm trying to create a discussion note on a merge request on a certain line of a file with the GitLab api using this endpoint: https://docs.gitlab.com/ee/api/discussions.html#create-new-merge-request-thread
Part of the payload asks for a line_code
Attribute
Type
Required
Description
position[line_range][start][line_code]
string
yes
Line code for the start line
When I issue a POST I get a response with:
"message": "400 (Bad request) \"Note {:line_code=>[\"can't be blank\", \"must be a valid line code\"], :position=>[\"is incomplete\"]}\" not given"
What is this line_code? Is it some kind of calculated value? The documentation is rather vague here.
When I issue a GET for all the current notes on a merge_request I can see some notes have this line_code (see below). I'm trying to figure out how to create that value for new notes.
{
"id": 89,
"type": "DiffNote",
"body": "4",
"attachment": null,
"author": {
"id": 6,
"name": "brian c",
"username": "bc",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/f590a9cf57136732dd0cb5z9b1563390?s=80&d=identicon",
"web_url": "http://gitlab.mycompany.us/thisIsMe"
},
"created_at": "2021-01-11T21:46:23.861Z",
"updated_at": "2021-01-11T21:46:23.861Z",
"system": false,
"noteable_id": 21,
"noteable_type": "MergeRequest",
"position": {
"base_sha": "3bf8094f0d54fc70a66698bd582f25c77243de3b",
"start_sha": "3bf8094f0d54fc70a66698bd582f25c77243de3b",
"head_sha": "a10e73cf84eae38286df56f4b58fa221d7eefc44",
"old_path": "b.txt",
"new_path": "b.txt",
"position_type": "text",
"old_line": null,
"new_line": 4,
"line_range": {
"start": {
"line_code": "aceba96ffdf13ce4cd4171c0248420cc03108ef0_0_4",
"type": "new",
"old_line": null,
"new_line": 4
},
"end": {
"line_code": "aceba96ffdf13ce4cd4171c0248420cc03108ef0_0_4",
"type": "new",
"old_line": null,
"new_line": 4
}
}
},
"resolvable": true,
"resolved": false,
"resolved_by": null,
"confidential": false,
"noteable_iid": 3,
"commands_changes": {}
},
Line code is hash of the file name + underscore + old line number + underscore + new line number
The documentation is wrong. line_code is required only if you are using position.line_range which is only required for adding diff note spanning multiple lines of diff. You don't need to deal with line_code for single-line diff notes. So it is not a required parameter. You can just use position.old_line or position.new_line.
That represents the line in the file you want the comment to appear on. For Merge Requests, comments can either be on the code or general discussions (though the API names seem to be backwards).
To add a general discussion comment, you can use the Notes API: https://docs.gitlab.com/ee/api/notes.html#create-new-merge-request-note. This will look like the comment here: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52673#note_495396729
To add a comment to the changed code in a Merge Request, you can use the Discussions API here: https://docs.gitlab.com/ee/api/discussions.html#create-new-merge-request-thread. This operation has options to set the file path and line number a comment should start on, a range that a comment applies to, etc. This is an example of a comment on the code itself: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52673/diffs#2eda52c44979de93f257b305ada778372eacba0b_6_5
It's not a bug, I meet this scene before.
maybe your "old_line" is not really exist.
just let set old_line and old_path to null
it will work normally.

Issue parsing XLIFF with node XML parser

Im trying to parse XLIFF file using xml2js library. All is working fine but if I have something like that: <source>Welcome to <x id="INTERPOLATION" equiv-text="{{ title }}"/> my friend</source> I will get [{"_":"Welcome to my friend","x":[{"$":{"id":"INTERPOLATION","equiv-text":"{{ title }}"}}]}]. I am basically loosing order for the parts of the sentence. I would expect to get an array of 3 parts:
"Welcome to "
[{"$":{"id":"INTERPOLATION","equiv-text":"{{ title }}"}}]
" my friend"
But instead Im getting:
"Welcome to my friend"
[{"$":{"id":"INTERPOLATION","equiv-text":"{{ title }}"}}]
If I would try to recreate string again I would get <source>Welcome to my friend<x id="INTERPOLATION" equiv-text="{{ title }}"/></source>
Any idea how to solve it with this XML parser or any other?
you also might like txml. When using it like txml.parse(yourXMLString), you get an object like this:
[
{
"tagName": "source",
"attributes": {},
"children": [
"Welcome to ",
{
"tagName": "x",
"attributes": {
"id": "INTERPOLATION",
"equiv-text": "{{ title }}"
},
"children": []
},
" my friend"
]
}
]
I think it looks absolutely as what you are looking for. The three children inside the source, are very clean to use. Also, this parser is only 4kb in size and there is no need for native c compiling that will cause difficulties when running your app on a different architecture.
Disclaimer: I am the author of txml, and this opinion might not be objective ;-)
With fast-xml-parser.
Please, use stopNodes in options when you parse the source.
It makes fast-xml to treat the content as plain-strings
var parser = require("fast-xml-parser");
parser.parse(srcFile, {ignoreAttributes: false, stopNodes: ["source", "target"],});

My model can't find any entities

I'm testing NLP tools and right now I'm facing a problem with Rasa NLU.
With API.AI, Wit.ai and LUIS.AI I could find the entities I want with no more than 8-10 examples. With Rasa, on the other hand, I already have 18 examples and I could never find an entity. Even if my query matches exactly one of my examples, I still have an empty entities array as the result.
I'm using Rasa with the recommended Docker instance and my current pipeline is ["nlp_spacy", "tokenizer_spacy", "intent_featurizer_spacy", "ner_crf", "ner_synonyms", "intent_classifier_sklearn" and "ner_duckling"].
I specify my project and my model within my query, like this:
localhost:5000/parse?q=my_sentence&project=my_project&model=my_model
Any useful information is appreciated.
Thank you!
Update with examples
{
"text": "How can I make a carrot cake?",
"intent": "AskRecipe",
"entities": [
{
"start": 17,
"end": 27,
"value": "carrot cake",
"entity": "recipe"
}
]
},
{
"text": "What do I need to make a Lemon Pie?",
"intent": "AskRecipe",
"entities": [
{
"start": 25,
"end": 33,
"value": "Lemon Pie",
"entity": "recipe"
}
]
},
{
"text": "What do I need to make brownies?",
"intent": "AskRecipe",
"entities": [
{
"start": 23,
"end": 30,
"value": "brownies",
"entity": "recipe"
}
]
}
Then when I try, for instance, to extract information from "What do I need to make brownies?" (which is also listed as a example) this is the result:
{"entities": [], "intent": {"confidence": 0.8870822891508189, "name": "AskRecipe"}, "text": "What do I need to make brownies?", "intent_ranking": [{"confidence": 0.8870822891508189, "name": "AskRecipe"}, {"confidence": 0.11291771084918109, "name": "greet"}]}
I tried many other examples, but none of them worked.
I solved this problem.
In my config.json file, I updated my pipeline value to "scapy_sklearn" as opposed to ["nlp_spacy", "tokenizer_spacy", "intent_featurizer_spacy", "ner_crf", "ner_synonyms", "intent_classifier_sklearn" and "ner_duckling"].
Also, I restarted my docker instance after I trained a new model.
I must say, though, the docker instance with which I succeeded is not the same as the one I was using when I posted this issue, so, honestly, I can't be 100% sure I didn't break any configuration before - although I believe I didn't.
I hope this helps someone :)
I had the same issue of Rasa not recognizing entities. I see you've solved the issue in a different way, I'll just add what worked for me cos I see the same mistake I made, in the examples posted -
The end value must be ('start' index) + (length of 'value') so it should be every 'end' value shown here +1.
I know it's very simple, but it worked for me.

Identifying numbers correctly

I have an intent where I might say 'Transfer 4 to Bob' and it identifies this as 'Transfer for to Bob'
Also I might say 'Transfer 10 to Bob and it identifies this as 'Transfer 102 Bob' treating to word to as 2 on the end of the previous number.
What is the best way to get API.AI to recognise these parts correctly so 4 is not for and to is not 2?
You mentioned that you're using the Actions on Google platform. This means that speech recognition - the process of translating what the user says into text - is happening before the data gets to API.AI.
The problem you're experiencing is that Actions on Google is misrecognizing some numbers as words, e.g. four becomes for.
Because this happens before - and separately from - API.AI, you won't be able to fix the misrecognition.
Below, I'll explain how you can work around this issue in API.AI. However, it's also worth thinking about how you could make your conversation design as robust as possible so that issues like this are less likely to cause problems.
One way you could increase robustness would be to mark the number as a required parameter in API.AI so the user is prompted if it isn't detected due to a recognition error. In that case, the dialog would go like this:
User: Give me four lattes.
App: Sure, four lattes coming up.
User: Give me for lattes.
App: How many do you want?
User: Four.
App: Sure, four lattes coming up.
Regardless, here's a workaround you can use to help recover from misrecognition:
In your intent, provide examples of these commonly misrecognized values. Highlight and mark them as numbers.
Test out your intent out in the console and you'll see that "for" is now matched as a "number" entity with value "for".
In your fulfillment webhook, check the parameter for this value and convert it to the appropriate number using a dictionary. Here's the JSON for the above query:
{
"id": "994c4e39-be49-4eae-94b0-077700ef87a3",
"timestamp": "2017-08-03T19:50:26.314Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "Get me for lattes",
"action": "",
"actionIncomplete": false,
"parameters": {
"drink": "lattes",
"number": "for" // NOTE: Convert this to "4" in your webhook
},
"contexts": [],
"metadata": {
"intentId": "0e1b0e72-78ba-4c61-a4fd-a73788034de1",
"webhookUsed": "false",
"webhookForSlotFillingUsed": "false",
"intentName": "get drink"
},
"fulfillment": {
"speech": "",
"messages": [
{
"type": 0,
"speech": ""
}
]
},
"score": 1
},
"status": {
"code": 200,
"errorType": "success"
},
"sessionId": "8b0891c1-50c8-43c6-99c4-8f77261acf86"
}

Resources