I have searched for an answer but still cant find it. I guess I am doing something wrong but i can't figure out what it is. This is my typeahead code:
$('.zoek').typeahead({
name: 'items01',
prefetch: {
url: '/models/_global.json',
ttl: 1,
},
template: '<div id="breed">
<span>{{#lock}}<img src="/assets/img/lock-icon-small.png">{{/lock}}{{^lock}}<img src="/assets/img/empty-icon-small.png">{{/lock}}</span>
<span class="searchresult">{{value}}</span>
<span class="searchresult-type"> - {{type}} </span>
<span class="red">{{#popular}} - popular {{/popular}}</span>
<span class="red">{{#new}} - new {{/new}}</span>
</div>',
engine: Hogan
});
And this is my _global.json file:
{
"items": [
{"value":"making claims for ebook subscriptions",
"icon":"download-icon-small.png",
"type":"brochure",
"date":"12-10-2011",
"lock": false,
"popular": false,
"new": true,
"tag": ["ebook","claim"]},
{"value":"Claim discovery & Online Management Suite - English",
"icon":"download-icon-small.png",
"type":"case",
"date":"28-02-2010",
"lock": true,
"popular": false,
"new": false,
"tag": ["claim","online"]},
{"value":"Get access to all online ebook publishers ",
"icon":"download-icon-small.png",
"type":"factsheet",
"date":"17-08-2012",
"lock": false,
"popular": true,
"new": true,
"tag": ["online","ebook"]},
{"value":"Ebook catalogue in swetswise - howto",
"icon":"show-icon-small.png",
"type":"hint",
"date":"08-01-2009",
"lock": true,
"popular": false,
"new": false,
"tag": ["ebook","swetswise"]},
{"value":"Swetswise software improved: you can claim now!",
"icon":"download-icon-small.png",
"type":"press",
"date":"20-08-2002",
"lock": false,
"popular": true,
"new": false,
"tag": ["swetswise","claim"]}
]
}
The Json file can't have an other format because some other code is relying on this format. Prefetch is not working and I guess I have to use a filter. Tried all kind of filter examples i could find but nothing seems to work. What am I doing wrong.
p.s.
(When I leave out the top curly brackets and the key "items" in the json file it is all working, so there are no problems with the js. libraries and Hogan)
Hope someonecan help me.
regards. M.dekker
After a good sleep and some thinking and found the answer to my question.
adding the following code in the prefetch block solved my problem:
filter: function(data){
// filter the returned data
return data.items;
}
Related
I would like to ask for some help with the conversion of a nested json into pandas df.
I have read the quite brilliant input from a couple of year past, but that is outdated now. :(
Flatten double nested JSON
So here is a sample of my input data (mind that classes might contain up to 10 class name and confidence pairs):
[
{
"classifier_id": "my_classifier_id",
"url": "https://api.eu-de.natural-language-classifier...",
"text": "for sales? aligning obsolete incentive\u00a0 system to what is the standard today: 100% reference salary, 100% of ref sal if you hit 100% of your quota",
"top_class": "conditions",
"classes": [
{
"class_name": "conditions",
"confidence": 0.9074866214536228
},
{
"class_name": "temperature",
"confidence": 0.09251337854637723
}
]
},
{
"classifier_id": "my_classifier_id",
"url": "https://api.eu-de.natural-language-classifier...",
"text": "Complete integration of incentives.\u00a0 People act inline with how they are compensated as the general rule. \u00a0 If we get that right then this model can genuinely change the face of IBM to the client.",
"top_class": "conditions",
"classes": [
{
"class_name": "conditions",
"confidence": 0.9683663322166756
},
{
"class_name": "temperature",
"confidence": 0.0316336677833244
}
]
},
{
"classifier_id": "my_classifier_id",
"url": "https://api.eu-de.natural-language-classifier.watson...",
"text": "Enablement, operational support on the most basic things",
"top_class": "temperature",
"classes": [
{
"class_name": "temperature",
"confidence": 0.8174158442711534
},
{
"class_name": "conditions",
"confidence": 0.1825841557288465
}
]
}
]
What I have tried thus far in python:
data_df = pd.read_json(r'C:\Users\...\Documents\Python NLP\WATSON NLC\OUTPUT JSON\nlc_data_full.json')
When using this the classes still remain in a json like form:
[{'class_name': 'conditions', 'confidence': 0.907486621453622}, {'class_name': 'temperature', 'confidence': 0.092513378546377}]
[{'class_name': 'conditions', 'confidence': 0.9683663322166751}, {'class_name': 'temperature', 'confidence': 0.031633667783324}]
[{'class_name': 'temperature', 'confidence': 0.8174158442711531}, {'class_name': 'conditions', 'confidence': 0.182584155728846}]
I would love to get a format that can be worked on in excel. Thank you for looking into this.
Well I think I managed to figure out what everyone already knew anyways. LOL
So the magic is in the pd.json_normalize function. With the parameters it takes it basically is able to open multinested json files with relative ease.
Also the pandas site has been a good friend as always: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.json_normalize.html
I am calling my dataset: nlc_data = [ .......
Here is a super lightweight solution for cases that do not have such intricate nesting: normie_2 = pd.json_normalize(nlc_data, max_level=0)
This one works for multi nested json files:
result = pd.json_normalize(nlc_data, 'classes', ['text', 'top_class'])
Well I guess I got a lot smarter today. Bare with me ... I just might have another awesome questions tomorrow.
Bye, Levi
I want to parse this JSON data but I have no idea how can I parse it.
{
"kind": "Testing",
"data": {
"modhash": "fffffghhhhhhbf0bb4601d6158db548b5296632215a0",
"dist": 75,
"children": [
{
"kind": "z4",
"data": {
"subreddit": "iOS",
"selftext": "I am iOS developer",
"author_fullname": "tyy_iif5q",
"saved": false,
"gilded": 0,
"clicked": false,
"title": "When is a good time to use docker?",
"subreddit_name_prefixed": "r/webdev",
"hidden": false,
"pwls": 6,
"downs": 0,
"hide_score": false,
"name": "t3_gwqan4",
"quarantine": false,
"link_flair_text_color": "dark",
"upvote_ratio": 0.96,
"subreddit_type": "public",
"ups": 277,
"total_awards_received": 0,
"is_original_content": false,
"is_reddit_media_domain": false,
"is_meta": false,
"can_mod_post": false,
"score": 277,
"author_premium": false,
"thumbnail": "self",
"edited": false,
"is_self": true,
"created": 1591333752,
"link_flair_type": "text",
"wls": 6,
"author_flair_type": "text",
"domain": "self.webdev",
"allow_live_comments": false,
"selftext_html": "<!-- SC_OFF --><div class=\"md\"><p>I just finished part 7 of the Full Stack Open course (<a href=\"https://www.fullstackopen.com/en\">www.fullstackopen.com/en</a>) and due to graphQL and typescript not being within the core content of the course, I thought I might try and learn docker. </p>\n\n<p>Turns out, trying to learn docker is just making me even more confused than when I didn't even know docker existed. </p>\n\n<p>​</p>\n\n<p>Could someone explain to me, when is a good time to use docker? How one would go about using docker, and when in someone's learning path would one ideally learn docker?</p>\n\n<p>​</p>\n\n<p>I am still learning react, databases, and overall front-end and back-end web development currently. The most I have done thus-far is hosting an app I made on heroku. I haven't setup a personal website, portfolio, or hosted an app on an independent website either.</p>\n</div><!-- SC_ON -->",
"archived": false,
"no_follow": false,
"is_crosspostable": true,
"pinned": false,
"over_18": false,
"media_only": false,
"can_gild": true,
"spoiler": false,
"locked": false,
"visited": false,
"subreddit_id": "t5_2qs0q",
"id": "gwqan4",
"is_robot_indexable": true,
"author": "Sensualities",
"num_comments": 127,
"send_replies": true,
"whitelist_status": "all_ads",
"contest_mode": false,
"author_patreon_flair": false,
"permalink": "/r/webdev/comments/gwqan4/when_is_a_good_time_to_use_docker/",
"parent_whitelist_status": "all_ads",
"stickied": false,
"url": "https://www.reddit.com/r/webdev/comments/gwqan4/when_is_a_good_time_to_use_docker/",
"subreddit_subscribers": 487697,
"created_utc": 1591304952,
"num_crossposts": 1,
"is_video": false
}
},
{
"kind": "t3",
"data": {
"subreddit": "iOS",
"selftext": "I am iOS developer",
"author_fullname": "tyy_iif5q",
"saved": false,
"gilded": 0,
"clicked": false,
"title": "When is a good time to use docker?",
"subreddit_name_prefixed": "r/webdev",
"hidden": false,
"pwls": 6,
"downs": 0,
"hide_score": false,
"name": "t3_gwqan4",
"quarantine": false,
"link_flair_text_color": "dark",
"upvote_ratio": 0.96,
"subreddit_type": "public",
"ups": 277,
"total_awards_received": 0,
"is_original_content": false,
"is_reddit_media_domain": false,
"is_meta": false,
"can_mod_post": false,
"score": 277,
"author_premium": false,
"thumbnail": "self",
"edited": false,
"is_self": true,
"created": 1591333752,
"link_flair_type": "text",
"wls": 6,
"author_flair_type": "text",
"domain": "self.webdev",
"allow_live_comments": false,
"selftext_html": "<!-- SC_OFF --><div class=\"md\"><p>I just finished part 7 of the Full Stack Open course (<a href=\"https://www.fullstackopen.com/en\">www.fullstackopen.com/en</a>) and due to graphQL and typescript not being within the core content of the course, I thought I might try and learn docker. </p>\n\n<p>Turns out, trying to learn docker is just making me even more confused than when I didn't even know docker existed. </p>\n\n<p>​</p>\n\n<p>Could someone explain to me, when is a good time to use docker? How one would go about using docker, and when in someone's learning path would one ideally learn docker?</p>\n\n<p>​</p>\n\n<p>I am still learning react, databases, and overall front-end and back-end web development currently. The most I have done thus-far is hosting an app I made on heroku. I haven't setup a personal website, portfolio, or hosted an app on an independent website either.</p>\n</div><!-- SC_ON -->",
"archived": false,
"no_follow": false,
"is_crosspostable": true,
"pinned": false,
"over_18": false,
"media_only": false,
"can_gild": true,
"spoiler": false,
"locked": false,
"visited": false,
"subreddit_id": "t5_2qs0q",
"id": "gwqan4",
"is_robot_indexable": true,
"author": "Sensualities",
"num_comments": 127,
"send_replies": true,
"whitelist_status": "all_ads",
"contest_mode": false,
"author_patreon_flair": false,
"permalink": "/r/webdev/comments/gwqan4/when_is_a_good_time_to_use_docker/",
"parent_whitelist_status": "all_ads",
"stickied": false,
"url": "https://www.reddit.com/r/webdev/comments/gwqan4/when_is_a_good_time_to_use_docker/",
"subreddit_subscribers": 487697,
"created_utc": 1591304952,
"num_crossposts": 1,
"is_video": false
}
}
],
"after": "ggggggg"
}
}
I want to parse this JSON data but I have no idea how can I parse it.I worked with simple json but I have no idea how can I parse nested json please help me. I want to parse this JSON data but I have no idea how can I parse it.I worked with simple json but I have no idea how can I parse nested json please help me.
Take a look at this library, it will help you ;)
https://pub.dev/packages/json_serializable
This lib will generate conversion code fromJson and toJson for each model annotated with #JsonSerializable
It take care of nested objects, type conversion and many other things ;)
Use this link to prepare model class of Json
https://javiercbk.github.io/json_to_dart/
HttpResponse response = callApi;
then after getting response just use json.decode;
then use fromjson Method of your Model generated through link and your whole json is parsed
Map userMap = jsonDecode(jsonString);
var user = User.fromJson(userMap);
User is Model created from site
At first you need a classes representing JSON with the method fromJson which parses JSON into your object.
Also you should use nested classes for nested JSON fields
Alternatively, you could generate necessary classes with this class generator
class JSONRepresentation {
final String kind;
final Data data;
JSONRepresentation({this.kind, this.data});
JSONRepresentation .fromJson(Map<String, dynamic> data)
: kind = data['kind'],
data = Data .fromJson(data['data']);
}
class Data {
final String modhash;
final int dist;
//final List<AnotherDataClass> children;
final String after;
Data({this.modhash, this.dist, this.after});
Data .fromJson(Map<String, dynamic> data)
: modhash = data['modhash'],
dist = data['dist'],
after = data['after'];
}
And then you can parse it using dart:convert and get data from objects representing JSON as below
import "dart:convert";
void main() {
var jsonData =
'{"kind": "Testing",
"data": {
"modhash": "fffffghhhhhhbf0bb4601d6158db548b5296632215a0",
"dist": 75,
//"children": [...],
"after": "ggggggg"}}';
var parsedJson = json.decode(jsonData);
var jsonRepresentationObject = JSONRepresentation.fromJson(parsedJson);
//Example of getting data from objects representing JSON
print("kind: "+ jsonRepresentationObject.kind +
"\nData modhash: " + jsonRepresentationObject.data.modhash);
}
You could test my example here - online dart compiler
I've configured my "polymer build" (v 2.0) to transpile an ES5 version just for IE 11, but now I need to serve only that version for IE 11 users and the ES6 version for all other browsers. What's the best way to achieve this?
Ideally, I'd like to use just one import in whichever client pages use my custom element and have some logic on the server to dish out the appropriate version, but being a newbie to web components, I don't want roll my own solution (which will probably be nasty) if there's a "right way" of doing it (so far I haven't found it, but I'll keep searching).
Thanks.
You should use a webserver, which is capable of detecting the browsers features.
The Polymer Team itself has released a library for nodeJS, which reads in your polymer.json file and looks in your builds directory and serves the correct build according to the features the browser of the client supports. The server itself supports H2 Push aswell, which is a nice feature.
https://github.com/Polymer/prpl-server-node
This is my builds configuration in polymer.json. It generates a different build for each capability. I cross checked, what versions of browsers support these technologies and added a build for each neccecary combination.
"builds": [{
"name": "none",
"browserCapabilities": [],
"addServiceWorker": true,
"bundle": true,
"swPrecacheConfig": "sw-precache-config.js",
"insertPrefetchLinks": true,
"js": {
"minify": true,
"compile": true
},
"css": {"minify": true},
"html": {"minify": true}
},
{
"name": "noes6",
"browserCapabilities": ["push", "serviceworker"],
"addServiceWorker": true,
"addPushManifest": true,
"swPrecacheConfig": "sw-precache-config.js",
"insertPrefetchLinks": true,
"js": {
"minify": true,
"compile": true
},
"css": {"minify": true},
"html": {"minify": true}
},
{
"name": "nopush",
"browserCapabilities": ["es2015", "serviceworker"],
"addServiceWorker": true,
"swPrecacheConfig": "sw-precache-config.js",
"insertPrefetchLinks": true,
"bundle": true,
"js": {"minify": true},
"css": {"minify": true},
"html": {"minify": true}
},
{
"name": "all",
"browserCapabilities": ["es2015", "push", "serviceworker"],
"addServiceWorker": true,
"addPushManifest": true,
"swPrecacheConfig": "sw-precache-config.js",
"js": {"minify": true},
"css": {"minify": true},
"html": {"minify": true}
}]
And a simple express server, which utilizes the prpl-server library for differential serving (bare in mind, that this is ES6 Syntax):
const prpl = require('prpl-server');
const express = require('express');
const config = require('./build/polymer.json');
const app = express();
app.get('/*', prpl.makeHandler('./build/', config));
app.listen(process.env.PORT || 80);
This is a sample of the json file that I've imported into my mongodb, I want build a basic index on it to search fields for relationship.
{
"business_id":"93otbGHE0s0m-lU1osvg9w",
"name":"Rivertowne",
"neighborhood":"North Side",
"address":"337 N Shore Dr",
"city":"Pittsburgh",
"state":"PA",
"postal_code":"15212",
"latitude":40.4459861,
"longitude":-80.0108802,
"stars":3.0,
"review_count":102,
"is_open":1,
"attributes":[
"Alcohol: full_bar",
"Ambience: {'romantic': False, 'intimate': False, 'classy': False, 'hipster': False, 'divey': False, 'touristy': False, 'trendy': False, 'upscale': False, 'casual': True}",
"BestNights: {'monday': False, 'tuesday': False, 'friday': True, 'wednesday': False, 'thursday': False, 'sunday': True, 'saturday': True}",
"BikeParking: True",
"BusinessAcceptsCreditCards: True",
"BusinessParking: {'garage': False, 'street': True, 'validated': False, 'lot': False, 'valet': False}",
"Caters: False",
"CoatCheck: False",
"GoodForDancing: False",
"GoodForKids: True",
"GoodForMeal: {'dessert': False, 'latenight': False, 'lunch': True, 'dinner': True, 'breakfast': False, 'brunch': False}",
"HappyHour: True",
"HasTV: True",
"Music: {'dj': False, 'background_music': False, 'no_music': False, 'karaoke': False, 'live': False, 'video': False, 'jukebox': False}",
"NoiseLevel: loud",
"OutdoorSeating: True",
"RestaurantsAttire: casual",
"RestaurantsDelivery: False",
"RestaurantsGoodForGroups: True",
"RestaurantsPriceRange2: 2",
"RestaurantsReservations: False",
"RestaurantsTableService: True",
"RestaurantsTakeOut: True",
"Smoking: no",
"WheelchairAccessible: True",
"WiFi: free"
],
"categories":[
"American (New)",
"Pubs",
"Nightlife",
"Bars",
"Restaurants"
],
"hours":null,
"type":"business"
}
But after I imported into json, the count and find all turn up zero. An expert told me the json file was not formatted the right way, so it won't fit my mongdb requirement. I have to find a different version of this json file.
Is there way to fix this?
attribute
GoodForDancing: True
And attribute
RestaurantsAttire: casual
--------------------PART B.-----------------
GoodForDancing: True
And attribute
RestaurantsAttire: dressy
I want to compare some things, out of restaurants with the attribute "Good For Dancing" I want to see how many have casual vs. dressy attire. I want to do a query search for both part using key, but so far count and find showed up 0.
This is my import command, business is the collection name and yep is the dbname:
mongoimport --db yelp --collection business --file /home/dachen/Desktop/business.json
My find command turned up nothing, so obviously json file is something wrong with it
db.business.find({ "attributes.GoodForDancing" : { $exists : true } })
People say the syntax is wrong, "", anyway way to fix it?
My DataTable is loaded almost entirely from the server side and I would like to keep as much processing as possible on the server to reduce the workload on the client.
By formatting I mean changing color, size, font, font-weight, adding icons and html tags... For example when a row or a few cells need to be highlighted or displayed in a specific way.
I'm thinking about using the render parameter, but I didn't find a way to set it in JSON:
render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) }
An example would also be the following snippet, but it does not provide enough separation between the client and server:
{
"doc": "<strong>546546545<strong>",
"nothing": 0.0,
"order": "<div class="shipped">98745</div>"
}
While I was able to find resources on how to fetch data from the server, I can't find information on how to pass formatting data as part of the json.
Is there a way to paste formatting options in my current DataTable format to make it also optimal? What alterations need to be done?
http://jsfiddle.net/ebRXw/1004/
JSON:
{
"columns": [
{
"data": "doc",
"title": "Doc."
},
{
"data": "order",
"title": "Order no."
},
{
"data": "nothing",
"title": "Nothing"
}
],
"data": [
{
"doc": "564251422",
"nothing": 0.0,
"order": "56421"
},
{
"doc": "546546545",
"nothing": 0.0,
"order": "98745"
}
]
}
JS:
this.table = $('#example').DataTable({
data: json.rows,
columns: json.columns,
select: true,
responsive: true,
rowReorder: true,
colReorder: true,
scrollY: 680,
deferRender: true,
scroller: true
});
HTML:
<table id="example" cellspacing="0" width="100%" />