Display data from common topic in Freebase using jQuery - javascript

I am playing around with Freebase and have had some decent success, but have hit a wall. My MQL is below. I do not have any issue displaying name,latin name, etc, which I created in my base. I do not know how to display the article which is in a different base.
Here is the jQuery I am using to display data:
$('<div>',{text:this.name}).appendTo(document.body);
Thank you very much,
Todd
query : [
{
"/common/topic/article": {
"guid": null,
"limit": 1,
"optional": true
},
"/common/topic/image": {
"id": null,
"limit": 1,
"optional": true
},
"id": null,
"larval_food": [
{
"index": null,
"lang": "/lang/en",
"limit": 6,
"optional": true,
"sort": "index",
"type": "/type/text",
"value": null
}
],
"latin_name": [
{
"index": null,
"lang": "/lang/en",
"limit": 6,
"optional": true,
"sort": "index",
"type": "/type/text",
"value": null
}
],
"limit": 60,
"name": null,
"s0:type": [
{
"id": "/base/butterflies/butterfly",
"link": [
{
"timestamp": [
{
"optional": true,
"type": "/type/datetime",
"value": null
}
],
"type": "/type/link"
}
],
"type": "/type/type"
}
],
"sort": "-s0:type.link.timestamp.value",
"type": "/base/butterflies/butterfly"
}
]

Change
"type": "/base/butterflies/butterfly"
to the type of the thing you actually want to include.
As an aside, that looks like a query which was exported from one of the Freebase.com view pages. It can be greatly simplified and some of the stuff, like the sorting, you probably want removed altogether.
Here's your query simplied (I also recommend using the standard scientific name property instead of inventing your own "Latin name" property):
[{
"type": "/base/butterflies/butterfly",
"mid": null,
"name": null,
"/common/topic/article": [],
"/common/topic/image": ["mid":null,"optional":true],
"larval_food": [],
"latin_name": [],
"/biology/organism_classification/scientific_name" : [],
}]
Here's a version of the query which shows all organism classifications (species in this case) which have the tribe Danaini two levels up. It optionally decorates it with data (larval_food) from your base, if it exists:
[{
"type": "/biology/organism_classification",
"higher_classification": [{
"/biology/organism_classification/higher_classification": "Danaini"
}],
"mid": null,
"name": null,
"scientific_name": [],
"/common/topic/article": [],
"/common/topic/image": [{
"mid": null,
"optional": true
}],
"/base/butterflies/butterfly/larval_food": [],
}]
You can try it here: http://tinyurl.com/6wht7lx

Related

JSON not indexing correctly

I have this JSON:
[
{
"type": "GUILD_TEXT",
"deleted": false,
"guild": "898666651547996200",
"guildId": "898666651547996200",
"parentId": "903388176100495390",
"permissionOverwrites": [
"900991433576689675",
"917426278003523604",
"898666651547996200",
"898825198709641246"
],
"messages": [
"928781911982219307"
],
"threads": [],
"nsfw": false,
"id": "903388255528042566",
"name": "updates",
"rawPosition": 41,
"topic": null,
"lastMessageId": "928781911982219307",
"rateLimitPerUser": 0,
"createdTimestamp": 1635454944260
}
]
(call = the json)
Shouldn't this be returning "updates": call[0]["name"]
Via JS, it is returning undefined.
call[0] is returning as {
I've tried it on various other languages and it has been working as intended... just not in JS.
It does work:
const call = [{
"type": "GUILD_TEXT",
"deleted": false,
"guild": "898666651547996200",
"guildId": "898666651547996200",
"parentId": "903388176100495390",
"permissionOverwrites": [
"900991433576689675",
"917426278003523604",
"898666651547996200",
"898825198709641246"
],
"messages": [
"928781911982219307"
],
"threads": [],
"nsfw": false,
"id": "903388255528042566",
"name": "updates",
"rawPosition": 41,
"topic": null,
"lastMessageId": "928781911982219307",
"rateLimitPerUser": 0,
"createdTimestamp": 1635454944260
}]
console.log(call[0]["name"]) // updates
const callString = JSON.stringify(call)
console.log(JSON.parse(callString)[0]["name"]) // updates
I tried
var name= call[0].name;
and
var name= call[0]["name"];
evertything is working properly returning "updates".

How to load 3D model to Three JS (JSON Format)

I need to import a JSON file which contains information about a 3D model for Three JS.
I have the boiler code for Three JS, I also have a loader function:
const loader = new THREE.ObjectLoader();
loader.load(
// resource URL
"modell.json",
// onLoad callback
// Here the loaded data is assumed to be an object
function ( obj ) {
// Add the loaded object to the scene
scene.add( obj );
console.log(scene)
},
// onProgress callback
function ( xhr ) {
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
},
// onError callback
function ( err ) {
console.error( 'An error happened' );
}
);
While running this code I don't get any errors or warnings, but the model doesn't show.
The content of the JSON File if required:
{
"metadata": {
"version": 4.4,
"generator": "io_three",
"type": "Object"
},
"animations": [{
"fps": 29,
"tracks": [],
"name": "default"
}],
"images": [],
"textures": [],
"geometries": [{
"uuid": "EC53DCE4-C690-3888-9701-2800E0AFBE11",
"data": {
"skinWeights": [],
"influencesPerVertex": 2,
"normals": [],
"vertices": [],
"skinIndices": [],
"faces": [],
"metadata": {
"version": 3,
"generator": "io_three",
"bones": 0,
"uvs": 0,
"normals": 0,
"morphTargets": 0,
"materials": 0,
"vertices": 0
},
"animations": [],
"morphTargets": [],
"name": "defaultGeometry",
"bones": [],
"uvs": []
},
"materials": [],
"type": "Geometry"
}],
"materials": [{
"uuid": "7F7EA3D4-7ACA-326E-BEE4-3EA415B8E912",
"blending": "NormalBlending",
"type": "MeshPhongMaterial",
"shininess": 50,
"emissive": 0,
"specular": 131586,
"color": 8355711,
"ambient": 8355711,
"depthTest": true,
"depthWrite": true,
"vertexColors": false,
"name": "armadillo_default"
}],
"object": {
"uuid": "A4515F76-5125-492C-9CF8-7B3B0E15D8BE",
"children": [{
"name": "armadillo2",
"uuid": "8AD86B53-F2E6-3978-A91C-657CCBEC6D8E",
"matrix": [-1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1],
"visible": true,
"type": "Object",
"children": [{
"name": "default",
"uuid": "E918B3CA-7846-3104-8C4D-FEB016A9E618",
"matrix": [0.972172,0,0,0,0,-0,-0.972172,0,0,0.972172,-0,0,-0.015785,0.021605,0,1],
"visible": false,
"type": "Mesh",
"material": "7F7EA3D4-7ACA-326E-BEE4-3EA415B8E912",
"castShadow": true,
"receiveShadow": true,
"geometry": "EC53DCE4-C690-3888-9701-2800E0AFBE11"
}]
}],
"matrix": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],
"type": "Scene"
}
}
What can I do to make my model show on the page.
I'm afraid your JSON file uses an outdated JSON format which can't be loaded anymore. You have to go back to r98 to load the JSON and then export it again with Scene.toJSON(). The resulting JSON is in the Object/Scene format 4 which can be loaded with the latest ObjectLoader again.

How to insert values of matching JSON Keys between 2 JSON files

I have 2 JSON files:
A Template JSON
A JSON output (from awscli)
The template is a small JSON file as below:
{
"DryRun": true,
"ImageId": "",
"KeyName": "",
"SecurityGroups": [
""
],
"InstanceType": "",
"Monitoring": {
"Enabled": false
},
"SubnetId": "",
"DisableApiTermination": true,
"PrivateIpAddress": "",
"IamInstanceProfile": {
"Arn": "",
"Name": ""
},
"EbsOptimized": true,
"TagSpecifications": [{
"ResourceType": "",
"Tags": [{
"Key": "",
"Value": ""
}]
}]
}
The original file is the output of aws ec2 describe-instances:
{
"Reservations": [{
"OwnerId": "123456789012",
"ReservationId": "r-12345678",
"Groups": [],
"Instances": [{
"Monitoring": {
"State": "disabled"
},
"PublicDnsName": "ec2-12-34-56-78.ap-southeast-1.compute.amazonaws.com",
"RootDeviceType": "ebs",
"State": {
"Code": 16,
"Name": "running"
},
"EbsOptimized": false,
"LaunchTime": "2016-02-09T03:06:21.000Z",
"PublicIpAddress": "12.34.56.78",
"PrivateIpAddress": "172.31.1.2",
"ProductCodes": [],
"VpcId": "vpc-1a2b3c4d",
"StateTransitionReason": "",
"InstanceId": "i-abcd1234",
"ImageId": "ami-1234abcd",
"PrivateDnsName": "ip-172-31-1-2.ap-southeast-1.compute.internal",
"KeyName": "tempKey",
"SecurityGroups": [{
"GroupName": "somegroup1",
"GroupId": "sg-ZZZZZ"
},
{
"GroupName": "somegroup2",
"GroupId": "sg-YYYYY"
}
],
"ClientToken": "NutKc123456789012",
"SubnetId": "subnet-00001234",
"InstanceType": "t2.medium",
"NetworkInterfaces": [{
"Status": "in-use",
"MacAddress": "02:AA:BB:CC:DD:EE",
"SourceDestCheck": true,
"VpcId": "vpc-1a2b3c4d",
"Description": "",
"Association": {
"PublicIp": "12.34.56.78",
"PublicDnsName": "ec2-12-34-56-78.ap-southeast-1.compute.amazonaws.com",
"IpOwnerId": "123456789012"
},
"NetworkInterfaceId": "eni-XXXXXXXX",
"PrivateIpAddresses": [{
"PrivateDnsName": "ip-172-31-1-2.ap-southeast-1.compute.internal",
"Association": {
"PublicIp": "1.2.3.4",
"PublicDnsName": "ec2-12-34-56-78.ap-southeast-1.compute.amazonaws.com",
"IpOwnerId": "123456789012"
},
"Primary": true,
"PrivateIpAddress": "172.31.1.2"
}],
"PrivateDnsName": "ip-172-31-1-2.ap-southeast-1.compute.internal",
"Attachment": {
"Status": "attached",
"DeviceIndex": 0,
"DeleteOnTermination": true,
"AttachmentId": "eni-attach-XXXXXXXX",
"AttachTime": "2016-01-13T08:33:37.000Z"
},
"Groups": [{
"GroupName": "somegroup1",
"GroupId": "sg-ZZZZZZ"
},
{
"GroupName": "somegroup2",
"GroupId": "sg-YYYYYY"
}
],
"Ipv6Addresses": [],
"SubnetId": "subnet-00001234",
"OwnerId": "123456789012",
"PrivateIpAddress": "172.31.1.2"
}],
"SourceDestCheck": true,
"Placement": {
"Tenancy": "default",
"GroupName": "",
"AvailabilityZone": "ap-southeast-1b"
},
"Hypervisor": "xen",
"BlockDeviceMappings": [{
"DeviceName": "/dev/xvda",
"Ebs": {
"Status": "attached",
"DeleteOnTermination": true,
"VolumeId": "vol-33221100",
"AttachTime": "2016-01-13T08:33:39.000Z"
}
}],
"Architecture": "x86_64",
"StateReason": {
"Message": "Client.UserInitiatedShutdown: User initiated shutdown",
"Code": "Client.UserInitiatedShutdown"
},
"RootDeviceName": "/dev/xvda",
"VirtualizationType": "hvm",
"Tags": [{
"Value": "SomeValue",
"Key": "SomeKey"
},
{
"Value": "AnotherValue",
"Key": "Name"
}
],
"AmiLaunchIndex": 0
}]
}]
}
I want to copy the values of the Keys in the original JSON file to the template file.
For example, KeyName is a common key between the 2 JSON files. The corresponding value tempKey is replaced in the template file.
The main use case of this is: I am trying to migrate a number of servers on AWS from 1 region to another. This is a part of migration process which will remove tons of manual clicking and configuration on AWS Console.
Note: I use BASH command line.
There's a way to do this with jq but it doesn't take a JSON template as input.
You'll have to modify it to become a query. This isn't the actual query you need, but something to get you started:
cat temp.json | jq '.Reservations[].Instances[] | { DryRun, ImageId, KeyName, SecurityGroups, InstanceType, Monitoring }'
Where temp.json is your output above that I placed into a file. For regular commands, just do something like aws ec2 describe-instances | jq ...
The output that gives me (keep in mind the restricted set I queried for) is:
{
"DryRun": null,
"ImageId": "ami-1234abcd",
"KeyName": "tempKey",
"SecurityGroups": [
{
"GroupName": "somegroup1",
"GroupId": "sg-ZZZZZ"
},
{
"GroupName": "somegroup2",
"GroupId": "sg-YYYYY"
}
],
"InstanceType": "t2.medium",
"Monitoring": {
"State": "disabled"
}
}
Hope this helps.

TypeError: Object [object Array] has no method 'getProperty'

I'm kind of new to this whole posting a question thing, so please be gentle!
I am using Breeze as part of the "Hot Towel" SPA stack and retrieving data from a custom WebApi endpoint written in PHP. It's not a full implementation, I've just written enough to give me what I need.
The metadata my endpoint is generating is as follows:
{
"shortName": "Project",
"namespace": "WebApi.ORM.Cartesius",
"autoGeneratedKeyType": "Identity",
"defaultResourceName": "Project",
"dataProperties": [
{
"name": "id",
"isPartOfKey": true,
"isNullable": false,
"dataType": "Int32"
},
{
"name": "title",
"isNullable": false,
"maxLength": 256,
"dataType": "String"
},
{
"name": "date",
"isNullable": false,
"dataType": "DateTime"
},
{
"name": "review_date",
"isNullable": true,
"dataType": "DateTime"
},
{
"name": "summary",
"isNullable": true,
"dataType": "String"
}
],
"navigationProperties": [
{
"name": "Team",
"entityTypeName": "Team:#WebApi.ORM.Cartesius",
"isScalar": true,
"associationName": "team_project_id_fkey",
"invForeignKeyNames": [
"project_id"
]
},
{
"name": "ProjectAuthor",
"entityTypeName": "ProjectAuthor:#WebApi.ORM.Cartesius",
"isScalar": true,
"associationName": "project_author_project_id_fkey",
"invForeignKeyNames": [
"project_id"
]
},
{
"name": "Itinerary",
"entityTypeName": "Itinerary:#WebApi.ORM.Cartesius",
"isScalar": true,
"associationName": "itinerary_project_id_fkey",
"invForeignKeyNames": [
"project_id"
]
},
Everything is working fine until I try and do an expand on my query:
var query = new breeze.EntityQuery()
.from("Project")
.where("id","eq",project.id)
.expand("ProjectAuthor");
This query returns the following from my endpoint:
[
{
"$id": 1,
"$type": "WebApi.ORM.Cartesius.Project",
"id": 2,
"title": "teat",
"date": "2013-11-04 14:00:00+07",
"review_date": null,
"summary": null,
"ProjectAuthor": [
{
"$id": 2,
"$type": "WebApi.ORM.Cartesius.ProjectAuthor",
"id": 1,
"account_id": 1,
"project_id": 2,
"Project": [
{
"$ref": 1
}
]
},
{
"$id": 3,
"$type": "WebApi.ORM.Cartesius.ProjectAuthor",
"id": 3,
"account_id": 2,
"project_id": 2,
"Project": [
{
"$ref": 1
}
]
}
]
}
]
Then Breeze chokes on it throwing:
TypeError: Object [object Array] has no method 'getProperty'
Debugging points to line 5059 in Breeze where it tries to getProperty on an array of entities rather than a single entity I assumed this had something to do with whether the navigation property was set to scalar or not but switching them around made no difference.
I'm sure I'm doing something massively wrong, but I can't figure out what it is and I've kind of hit a brick wall. I've read the docs from top to bottom and am implementing this as best as I can understand but it's possible I'm a little confused.
Thanks in advance for any help and apologies if I have not made myself clear or provided enough info
I think your problem is in the metadata
"name": "ProjectAuthor",
"entityTypeName": "ProjectAuthor:#WebApi.ORM.Cartesius",
"isScalar": true,
"associationName": "project_author_project_id_fkey",
"invForeignKeyNames": [
"project_id"
]
},
On that nav property Project->ProjectAuthor your telling it that its a scalar but its not in the data set..
"ProjectAuthor": [
{
..........
I've had this problem aswell .. 99% time its a metadata problem, if not there then start cutting metadata apart until you isolate the error .. though I'm sure thats the problem.. you need a hasMany there and an isScalar on the inverse navigation

how to return null composite objects in mql

I have been working on a simple calorie counter using freebase. When I am querying for a recipe I am not getting all the entries returned.
My query is:
[{
"id": "/m/0e cvb9k7",
"name": null,
"/food/recipe/ingredients": [{
"id": null,
"ingredient": {
"id": null,
"name": null,
"/food/food/energy": null
},
"unit": {
"id": null,
"name": null
},
"quantity": null
}]
}]
For example, in the gumbo recipe there are ingredients like onions or peppers where unit is null. Those are not returned by this query. How do I write a query that will return all the ingredients, including the ones with null units?
I tried:
"unit|=": [
null,
{
"id": null,
"name": null
}
]
This gave me an error Comparison operator |= takes a non-empty list of values.
Add "optional": true to that subquery viz
[{
"id": "/m/0e cvb9k7",
"name": null,
"/food/recipe/ingredients": [{
"id": null,
"ingredient": {
"id": null,
"name": null,
"/food/food/energy": null
},
"unit": {
"id": null,
"name": null
"optional":true
},
"quantity": null
}]
}]

Categories

Resources