How can I deal with a column containing a list of items - socrata

I want to make a dropdown of categories so I call https://data.seattle.gov/resource/n6as-h2bj.json?$select=categories&$group=categories Some of the rows have multiple categories. Is there anyway to handle this via SODA or do I have do it via javascript?

Sorry for the delay in getting back to you, #tim-clemans. I missed this one.
I assume you're referring to the values separated by pipe (|) characters, correct?
{
"categories": "Suspicious Circumstance|Alarm|Crisis"
},
{
"categories": "Traffic|Suspicious Circumstance"
},
Unfortunately there's no functionality to do that from right within SoQL. A str.split(/|/) should probably do the trick though

Related

How to break new line on Microsoft Sharepoint list column description?

Not sure if this is a good place to ask but I’m about an hour into editing a Sharepoint for the first time, have zero prior knowledge on creating/editing Sharepoints, and I’m stuck trying to figure out how to wrap text to a new line in the description field of a particular column on my list.
We need the submitters to stop at a certain point and not touch the remaining fields, and the only way I can figure out how to do that is by adding a column description that tells them to stop. I want the description of that column to read as:
————-—STOP ————-—
Submitters stop here. Do not use the fields below, unless attaching images/files. The remaining fields are for macro champ use only.
———————————————-
Instead of :
————-—STOP ————-—Submitters stop here. Do not use the fields below, unless attaching images/files. The remaining fields are for macro champ use only.———————————————-
Do I need to use JSON to achieve this? If so..what is the code I would need to use?
Also open to alternative solutions to create a line/stop/hide fields from them or something.
——————
ETA - photo of what my column formatting box looks like.
——————
ETA for further clarification -
The column in particular that I am trying to add the “stop” message to is actually named “Attachments included?” And has ‘yes’ or ‘no’ radio choice buttons. Then the description underneath that column says “submitters stop here, unless attaching images/files below.” This column, and it’s description, are hidden from the list overview and only visible when submitting a +New item.
The reason for doing this is because we have a handful of fields towards the end of the +New item submission form that we don’t want submitters to touch, as they are for the help desk agents to fill out only.
I don’t see any other way to add a stop/line or hide certain fields from the submitters (while still leaving them visible to the help desk team), so just trying to make this “stop” description look a little neater.
Format the column as shown below:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": " ————-—STOP ————-— \n\n Submitters stop here. Do not use the fields below, unless attaching images/files. The remaining fields are for macro champ use only. \n\n ———————————————",
"style": {
"width": "100%",
"font-weight": "bold"
}
}
Update:

How to add more XPATH in parsefilter.json in stormcrawler

I am using stormcrawler (v 1.16) & Elasticsearch(v 7.5.0) for extracting data from about 5k news websites. I have added some XPATH patterns for extracting author name in parsefilter.json.
Parsefilter.json is as shown below:
{
"com.digitalpebble.stormcrawler.parse.ParseFilters": [
{
"class": "com.digitalpebble.stormcrawler.parse.filter.XPathFilter",
"name": "XPathFilter",
"params": {
"canonical": "//*[#rel=\"canonical\"]/#href",
"parse.description": [
"//*[#name=\"description\"]/#content",
"//*[#name=\"Description\"]/#content"
],
"parse.title": [
"//TITLE",
"//META[#name=\"title\"]/#content"
],
"parse.keywords": "//META[#name=\"keywords\"]/#content",
"parse.datePublished": "//META[#itemprop=\"datePublished\"]/#content",
"parse.author":[
"//META[#itemprop=\"author\"]/#content",
"//input[#id=\"authorname\"]/#value",
"//META[#name=\"article:author\"]/#content",
"//META[#name=\"author\"]/#content",
"//META[#name=\"byline\"]/#content",
"//META[#name=\"dc.creator\"]/#content",
"//META[#name=\"byl\"]/#content",
"//META[#itemprop=\"authorname\"]/#content",
"//META[#itemprop=\"article:author\"]/#content",
"//META[#itemprop=\"byline\"]/#content",
"//META[#itemprop=\"dc.creator\"]/#content",
"//META[#rel=\"authorname\"]/#content",
"//META[#rel=\"article:author\"]/#content",
"//META[#rel=\"byline\"]/#content",
"//META[#rel=\"dc.creator\"]/#content",
"//META[#rel=\"author\"]/#content",
"//META[#id=\"authorname\"]/#content",
"//META[#id=\"byline\"]/#content",
"//META[#id=\"dc.creator\"]/#content",
"//META[#id=\"author\"]/#content",
"//META[#class=\"authorname\"]/#content",
"//META[#class=\"article:author\"]/#content",
"//META[#class=\"byline\"]/#content",
"//META[#class=\"dc.creator\"]/#content",
"//META[#class=\"author\"]/#content"
]
}
},
I have also made change in crawler-conf.yaml and it is as shown below.
indexer.md.mapping:
- parse.author=author
metadata.persist:
- author
The issue i am facing is : I am getting result only for 1st pattern (i.e. "//META[#itemprop="author"]/#content") of "parse.author". What changes I should do so that all patterns can be taken as input.
What changes I should do so that all patterns can be taken as input.
I read this as "How can I make a single XPath expression that tries all different ways an author can appear in the document?"
Simplest approach: Join the all expressions you already have into a single one with the XPath Union operator |:
input[...]|meta[...]|meta[...]|meta[...]
And since this potentially selects more than one node, we could state explicitly that we only care for the first match:
(input[...]|meta[...]|meta[...]|meta[...])[1]
This probably works but it will be very long and hard to read. XPath can do better.
Your expressions are all pretty repetitive, that's a good starting point to reduce the size of the expression. For example, those two are the same, except for the attribute value:
//meta[#class='author']/#content|//meta[#class='authorname']/#content
We could use or and it would get shorter already:
//meta[#class='author' or #class='authorname']/#content
But when you have 5 or 6 potential values, it still is pretty long. Next try, a predicate for the attribute:
//meta[#class[.='author' or .='authorname']]/#content
A little shorter, as we don't need to type #class all the time. But still pretty long with 5 or 6 potential values. How about a value list and a substring search (I'm using / as a delimiter character):
//meta[contains(
'/author/authorname/',
concat('/', #class, '/')
)]/#content
Now we can easily expand the list of valid values, and even look at different attributes, too:
//meta[contains(
'/author/authorname/article:author/',
concat('/', #class|#id , '/')
)]/#content
And since we're looking for almost the same possible strings across multiple possible attributes, we could use a fixed list of values that all possible attributes are checked against:
//meta[
contains(
'/author/article:author/authorname/dc.creator/byline/byl/',
concat('/', #name|#itemprop|#rel|#id|#class, '/')
)
]/#content
Combined with the first two points, we could end up with this:
(
//meta[
contains(
'/author/article:author/authorname/dc.creator/byline/byl/',
concat('/', #name|#itemprop|#rel|#id|#class, '/')
)
]/#content
|
//input[
#id='authorname'
]/#value
)[1]
Caveat: This only works as expected when a <meta> will never have both e.g. #name and #rel, or if, that they at least both have the same value. Otherwise concat('/', #name|#itemprop|#rel|#id|#class, '/') might pick the wrong one. It's a calculated risk, I think it's not usual for this to happen in HTML. But you need to decide, you're the one who knows your input data.

Adding newline and spacing in watson conversation output (JSON)

I want the watson conversation to give an output like:
I can solve the problems for the following products.
1 Air Conditioner
2 Refrigerator
3 Washing Machine
I am trying the following in JSON. But I am getting all the text cramped together.
{
"output": {
"text": "I can solve the problems for the following products.\n\n1\tAir Conditioner\n2\tRefrigerator\n3\tWashing Machine"
}
}
I have also tried \n and \t which is also unsuccessful. Is there any way to get the text properly spaced in the JSON text tag. (I used the conversation tool to everything)
I found the answer!!
add
"br" tags in the simple format of JSON. It is not reflected on the test chat, the change is only reflected on deploying it in an app
Try this:
{
"output": {
"text": ["I can solve the problems for the following products.",
"1\tAir Conditioner", "2\tRefrigerator", "3\tWashing Machine"
]
}
}
As per documentation:
To specify more than one statement that you want to display on separate lines, define the output as a JSON array.
The first sentence is displayed on one line, and the second sentence is displayed as a new line below it.
Source: https://console.bluemix.net/docs/services/conversation/dialog-build.html#responses

AngularJS - Conditionally display key and value if they exist

This may be a little confusing to describe.
Basically, I am parsing multiple external JSON feeds that display in different views depending on the 'active tab' displayed. They both share the same partial template, so they both look exactly the same, just different content.
The problem that I am facing now is, that in some feeds, some keys are placed in an array and others are not.
For example, the feeds parses this kind of data:
JSON Feed 1 - One 'attributes' inside of 'link'
"link":{
"attributes":{
"href":"www.link1.com"
}
}
JSON Feed 2 - Two 'attributes' inside of 'link'
"link":[
{
"attributes":{
"href":"www.link1.com"
}
},
{
"attributes":{
"href":"www.link2.com"
}
}
]
The only way I am able to get the value "www.link1.com" is via:
For Feed 1:
link1
And for Feed 2:
link1
I am trying to figure out what would be the best way to do:
1) If link[0] exists - display it, else if [link] exists, display that instead.
2) Or if targeting the activeTab would be safer? For instance, if activeTab = view2 or view4, use [link][0], else if activeTab = view1 or view3 use [link], else if I do not want it to be displayed, do not display anything.
Also a relatable question, if I am on view2 can I only display [link][0] on that view?
Any feedback would be appreciated. Thanks!
In your model controller, you can reconstruct the JSON objects to make them similar. The value of link in both feeds should be an array.
Then in your template you can simply use ngRepeat to get the items from inside the array.
Okay - so I found a solution to one of the questions above: "How to only display [link][0] in a specific view"
Pro: It's a simple code that depends on the activeTab / view that is being displayed.
Con(?): Since I am really a newbie to AngularJS - not sure if this is the best solution.
Basically:
Depending on the ng-view that is currently displayed, than a specific JSON object will be displayed, such as:
<a ng-show="activeTab == 'view1' || activeTab == 'view3'" ng-href="{{item['link'][0]['attributes']['href']}}">
<h6>Link1 from Feed2</h6>
</a>
Although the primary question is still unresolved: How to swap/switch JSON objects (key,values) if one exists, and not the other. I am still definitely trying to find a solution, although any help is still appreciated.
Please let me know what you think, or how I can improve the solution to the problem!
Thanks!
Roc.

How to Display Array Value to through Index in DUSTJS

My Question is simple: Is there anyway to display array value through its index in DUSTjs syntax.
Sample JSON :
{ names:
[
"Jhon",
"Peter",
"Curly"
]
}
with the above json sample, I just want to display any of the names through its index in DUST syntax.
Note: We are able to display all names, but i need any of the names to be displayed as output through its index (Eg : names[0] something like this or by any other way).
when iterating $idx will give you the index so for example showing them as <li> elements:
{#names}
<li>
{names[$idx]}
<li>{~n}
{/names}
otherwise just plain
{names[1]}
will give you first element
This is quite easy to achieve:
{names[0]} gives you Jhon
{names[2]} gives you Curly
and so on.. Hope this helps.
if you use the linkedin dustjs fork, you can do that:
take a look here: http://linkedin.github.com/dustjs/test/test.html. There are a lot of examples.
This is the wikki: https://github.com/linkedin/dustjs/wiki
and this is the code repo:
https://github.com/linkedin/dustjs