Google Sheets : formula, script or extension to get classification tags for images automatically? - google-sheets

I have a Google Sheet with a list of image URLs.
First column : image URLs.
Second column : tags describing the image (for example: "landscape, mountain, field, sunset, lake" for a landscape image with a mountain, field, sunset, etc...)
I would like to fill automatically my column 2 with a formula like "ImageTags(ImageUrl)".
Are there any formula, extension or script (already available :) ) for that?
Thanks !

An option is to use Google Cloud Vision API to label your images. You can test the API to decide whether it suits your needs or not here.
There are two tutorials using Google Apps Script to call the API that can help you develop the exact code that you need:
Using a service account to authenticate, detect labels and send a GMail message
Using oAuth2 to authenticate and label images
As an example, using the following image:
And calling the API with the following parameters:
HTTP Request
POST https://vision.googleapis.com/v1/images:annotate
Body
{
"requests": [
{
"image": {
"source": {
"imageUri": "https://i.stack.imgur.com/4vwKt.jpg"
}
},
"features": [
{
"type": "LABEL_DETECTION"
}
]
}
]
}
You obtain the following result (5 Nov 2019):
{
"responses": [
{
"labelAnnotations": [
{
"mid": "/m/09j06",
"description": "Hot air balloon",
"score": 0.9889263,
"topicality": 0.9889263
},
{
"mid": "/m/01j51",
"description": "Balloon",
"score": 0.95322704,
"topicality": 0.95322704
},
{
"mid": "/m/02p81ht",
"description": "Hot air ballooning",
"score": 0.9223063,
"topicality": 0.9223063
},
{
"mid": "/m/0cmqr_4",
"description": "Party supply",
"score": 0.9016293,
"topicality": 0.9016293
},
{
"mid": "/m/01d40f",
"description": "Dress",
"score": 0.86037284,
"topicality": 0.86037284
},
{
"mid": "/m/07yv9",
"description": "Vehicle",
"score": 0.7725018,
"topicality": 0.7725018
},
{
"mid": "/m/01bqvp",
"description": "Sky",
"score": 0.7326111,
"topicality": 0.7326111
},
{
"mid": "/m/0ds99lh",
"description": "Fun",
"score": 0.7039424,
"topicality": 0.7039424
},
{
"mid": "/m/016pp7",
"description": "Happy",
"score": 0.6789371,
"topicality": 0.6789371
},
{
"mid": "/m/06bm2",
"description": "Recreation",
"score": 0.6695586,
"topicality": 0.6695586
}
]
}
]
}

Related

Filter by Array Length in OData

I want to filter based on the length of data. For example, I want to retrieve only the images array that contains more than 1 element. Something like that images.length > 6.
Is this possible using OData. Your help is much appreciated
{
"#search.score": 1,
"site": "core",
"images": [
{
"alt": "Quad"
}
]
}, ,{
"#search.score": 1,
"site": "ccc",
"images": [
{
"alt": "some"
}
]
},
{
"#search.score": 1,
"site": "ccc",
"images": [
{
"alt": "DePaul's Student Center"
},
{
"alt": "O'Malley"
},
{
"alt": "Campus"
},
{
"alt": " Campus"
},
{
"alt": "ith students"
},
{
"alt": "er"
},
{
"alt": "df"
},
{
"alt": "sdf"
},
{
"alt": "df"
},
]
A simpler and better solution is to populate your data with an additional property called ImageCount. If you submit your items via the Azure Search SDK, you can process them before submitting them to search. Add the image count to each item and then filter like normal.
$filter=ImageCount gt 6

Rails - How to add pagination to Fastjson api?

The default result of rendering FastJsonApi gem serialized_json like below:
render json: FlashcardSerializer.new(flashcards).serialized_json
would be something like this:
{
"data": [
{
"id": "1",
"type": "flashcard",
"attributes": {
"question": "why?",
"answer": "pretty good",
"slug": null
}
},
{
"id": "2",
"type": "flashcard",
"attributes": {
"question": "What is 0",
"answer": "it is 0",
"slug": null
}
}
]
}
I would rather add some extra information especially for pagination and I like the result to be something like this:
{
"data": [
{
"id": "1",
"type": "flashcard",
"attributes": {
"question": "why?",
"answer": "pretty good",
"slug": null
}
},
{
"id": "2",
"type": "flashcard",
"attributes": {
"question": "What is 0",
"answer": "it is 0",
"slug": null
}
},
"count":100,
"page":1,
]
}
I am aware of other available gems that manage pagination in API, and I know how to do it without Fastjson. The main issue here is that is there any way to get the aforementioned result from this gem without changing a lot in the code. Thanks
The desired document would be invalid according to the JSON API specification. You would need to include next and previous links in a link section. The current and total_count would belong in the meta section.
{
"data": [
{
"id": "1",
"type": "flashcard",
"attributes": {
"question": "why?",
"answer": "pretty good",
"slug": null
}
},
{
"id": "2",
"type": "flashcard",
"attributes": {
"question": "What is 0",
"answer": "it is 0",
"slug": null
}
},
]
"meta": {
"page": { "current": 1, "total": 100 }
},
"links": {
"prev": "/example-data?page[before]=yyy&page[size]=1",
"next": "/example-data?page[after]=yyy&page[size]=1"
},
}
Have a look at the JSON API specification before you continue designing the API.
You can pass these information into the serializer as an options argument
class FlashcardsController < ApplicationController
def index
render json: FlashcardSerializer.new(
flashcards, { links: {}, meta: { page: { current: 1 } }
).serialized_json
end
end
How you generate the data depends what you use to paginate.
If you design a new API, I would also recommend to use cursor based pagination rather than offset pagination because of it's limitations.
https://github.com/Netflix/fast_jsonapi#compound-document
https://github.com/Netflix/fast_jsonapi/blob/master/spec/lib/object_serializer_spec.rb#L8-L32

How to Create a 3 level graph using NEO4J using JSON Array of Objects

I want to create a graph using neo4j which gives me a graph of the terms in the "JavaScript" array of the following JSON data, along with relationships pointing to unique "relatedTerms" nodes.
Here is my JSON data:
{
"JavaScript": [
{
"termName": "asm.js",
"link": "/terms/javascript/asmjs",
"info": "A subset of JavaScript. Effectively describes a safe virtual machine for memory-unsafe languages like C or C++. It can be used as a low-level, efficient target language for compilers.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
},
{
"name": "C",
"link": "/terms/go_to_term/470"
},
{
"name": "C++",
"link": "/terms/go_to_term/860"
},
{
"name": "compilers",
"link": "/terms/go_to_term/390"
}
],
"category": "JavaScript"
},
{
"termName": "Cycle.js",
"link": "/terms/javascript/cyclejs",
"info": "JavaScript framework for a predictable code. Builds on functional and reactive streams. Describes an app as a simple function taking an event stream as input and outputting an event stream.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
}
],
"category": "JavaScript"
},
{
"termName": "Derby",
"link": "/terms/javascript/derby",
"info": "Server component which is written on top of Node.js. It's is a server-side application with rich real-time data synchronization technology such used in google docs.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
},
{
"termName": "Express.js",
"link": "/terms/javascript/expressjs",
"info": "Lightweight, efficient middleware and routing framework. Express.js is best known as another quarter of the MEAN (MongoDB, Express, AngularJS and Node) software stack, and is the most popular Node.js framework.",
"relatedTerms": [
{
"name": "MEAN",
"link": "/terms/go_to_term/361"
},
{
"name": "MongoDB",
"link": "/terms/go_to_term/868"
},
{
"name": "AngularJS",
"link": "/terms/go_to_term/47"
},
{
"name": "Node",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
},
{
"termName": "Flow",
"link": "/terms/javascript/flow",
"info": "A static type checker for JavaScript. Integrates with the code editor by checking changes and analyzing correctness of the code. Provides context as to what is wrong with the code.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
}
],
"category": "JavaScript"
},
{
"termName": "Hapi",
"link": "/terms/javascript/hapi",
"info": "Web framework for building web applications, APIs and services. Hapi was created around the idea that configuration is better than code, that business logic must be isolated from the transport layer.",
"relatedTerms": [
{
"name": "APIs",
"link": "/terms/go_to_term/206"
}
],
"category": "JavaScript"
},
{
"termName": "Koa",
"link": "/terms/javascript/koa",
"info": "Callback-less, lightweight middleware framework for Node.js to build efficient web applications and APIs. Koa.js efficiently uses generators to deal with callbacks and increase error-handling capabilities.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
},
{
"name": "API",
"link": "/terms/go_to_term/206"
}
],
"category": "JavaScript"
},
{
"termName": "MEAN",
"link": "/terms/javascript/mean",
"info": "A full stack JavaScript solution that refers to the first letters of the four components of a solution for building dynamic websites: MongoDB, a NoSQL database; Express.js, a web applications framework; Angular.js, a JavaScript MVC framework for web apps; Node.js, a software platform for scalable server-side and networking applications.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
},
{
"name": "MongoDB",
"link": "/terms/go_to_term/868"
},
{
"name": "NoSQL",
"link": "/terms/go_to_term/951"
},
{
"name": "Express.js",
"link": "/terms/go_to_term/392"
},
{
"name": "Angular.js",
"link": "/terms/go_to_term/47"
},
{
"name": "MVC",
"link": "/terms/go_to_term/201"
},
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
},
{
"termName": "Meteor",
"link": "/terms/javascript/meteor",
"info": "JavaScript framework built on top of Node.js with MongoDB as its database driver. With Node.js and Meteor, you’re using JavaScript everywhere, and data is synced through the use of WebSockets, a protocol that allows an interactive communication between server and browser.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
},
{
"name": "MongoDB",
"link": "/terms/go_to_term/868"
},
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
},
{
"name": "WebSockets",
"link": "/terms/go_to_term/1046"
}
],
"category": "JavaScript"
},
{
"termName": "Node.js",
"link": "/terms/javascript/nodejs",
"info": "One of the most popular JavaScript frameworks which eases the work of building web applications. By far the fastest growing language in use. Runs on Windows, Linux, and Mac OS. The use of Node.js is mainly for full stack, front-end and back-end.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
},
{
"name": "Windows",
"link": "/terms/go_to_term/1373"
},
{
"name": "Linux",
"link": "/terms/go_to_term/558"
},
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
},
{
"termName": "Oracle JET",
"link": "/terms/javascript/oracle_jet",
"info": "Oracle JavaScript Extension Toolkit. A modular toolkit based on modern JavaScript, CSS3 and HTML5 design and development principles. Created for developers who work on applications that consume and interact with Oracle products and services.",
"relatedTerms": [
],
"category": "JavaScript"
},
{
"termName": "Restify",
"link": "/terms/javascript/restify",
"info": "A Node.js module built specifically to enable to build correct REST web services. It borrows heavily from express as that is more or less the de facto API for writing web applications on top of Node.js.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
},
{
"name": "REST",
"link": "/terms/go_to_term/524"
},
{
"name": "API",
"link": "/terms/go_to_term/206"
}
],
"category": "JavaScript"
},
{
"termName": "Sails",
"link": "/terms/javascript/sails",
"info": "Sails.js wraps express and provides another higher level for doing things like connecting to the DB, auto-generating input pages, etc. Especially suitable for creating chat apps or multiplayer games.",
"relatedTerms": [
{
"name": "DB",
"link": "/terms/go_to_term/415"
}
],
"category": "JavaScript"
},
{
"termName": "Seneca",
"link": "/terms/javascript/seneca",
"info": "Microservices toolkit for Node.js. Helps to write an organized code that can be scaled and deployed at any time. Organizes the business logic of an app.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
}
]
}
My Expected Result looks like:
The following is my Query:
CALL apoc.load.json("file:///js.json") YIELD value
UNWIND value.JavaScript AS item
FOREACH(js IN item |
CREATE(cat:Category{name:js.termName})
FOREACH(rt in item.relatedTerms|
CREATE(rtt:RelatedTerms{name:rt.name})
MERGE (cat)-[r:RELATESTO]->(rtt)))
And here is my Actual Result:
Try switching the CREATE statements for MERGE statements. In Cypher, MERGE will check to see if a pattern exists and create it if it does not. CREATE will create a new pattern every time, even if a pattern like it already exists in the graph.
CALL apoc.load.json("file:///js.json") YIELD value
UNWIND value.JavaScript AS item
MERGE (cat:Category {name:item.termName})
WITH cat, item
UNWIND item.relatedTerms AS subitem
MERGE (rt:RelatedTerm {name:subitem.name})
MERGE (cat)-[:RELATES_TO]->(rt)
RETURN *

Using YQL to get Options Data

Using the YQL console I did:
select * from yahoo.finance.options where symbol="FB"
but I got the following result in JSON. There is no data in the optionsChain. Based on other posts I believe the request to be formatted correctly. How do I get the data that should be in the options chain? Is this out of date or am I missing something? Thanks in advance.
{
"query": {
"count": 1,
"created": "2015-01-10T17:26:16Z",
"lang": "en-US",
"diagnostics": {
"url": [
{
"execution-start-time": "0",
"execution-stop-time": "71",
"execution-time": "71",
"content": "http://www.datatables.org/yahoo/finance/yahoo.finance.options.xml"
},
{
"execution-start-time": "74",
"execution-stop-time": "1620",
"execution-time": "1546",
"content": "http://finance.yahoo.com/q/op?s=FB"
}
],
"publiclyCallable": "true",
"log": [
"results.length(): 0",
"no elements"
],
"javascript": {
"execution-start-time": "74",
"execution-stop-time": "1647",
"execution-time": "1573",
"instructions-used": "11272",
"table-name": "yahoo.finance.options"
},
"user-time": "1648",
"service-time": "1537",
"build-version": "0.2.278"
},
"results": {
"optionsChain": {
"symbol": "FB"
}
}
}
}
Lots of people having problems with this myself included.
After looking around I found out that Google's Option information is also available via JSON.
It's no good for production environments as it's unsupported and really just a function of how there site operates, but if your interested I did a tutorial with full sample code on it. Even better it's REST based so can be consumed fairly easily in any language.
Google Stock Option Chain Data

rails geokit - get travel/commute time

Is there a way to use geokit in rails to get the estimated travel time between two locations? Right now, I'm simply showing the distance away but I think a better approach would be to show '15 minutes away' -- gives it a more practical approach to distance (sometimes 2 miles is 10 minutes and sometimes its 3)
A better solution would be to use the Google Maps Directions API using the API is as simple as calling the following URL http://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO|Oklahoma+City,OK&sensor=false.
Which returns this JSON:
{
"status": "OK",
"routes": [ {
"summary": "I-40 W",
"legs": [ {
"steps": [ {
"travel_mode": "DRIVING",
"start_location": {
"lat": 41.8507300,
"lng": -87.6512600
},
"end_location": {
"lat": 41.8525800,
"lng": -87.6514100
},
"polyline": {
"points": "a~l~Fjk~uOwHJy#P",
"levels": "B?B"
},
"duration": {
"value": 19,
"text": "1 min"
},
"html_instructions": "Head \u003cb\u003enorth\u003c/b\u003e on \u003cb\u003eS Morgan St\u003c/b\u003e toward \u003cb\u003eW Cermak Rd\u003c/b\u003e",
"distance": {
"value": 207,
"text": "0.1 mi"
}
},
...
... additional steps of this leg
...
... additional legs of this route
"duration": {
"value": 74384,
"text": "20 hours 40 mins"
},
"distance": {
"value": 2137146,
"text": "1,328 mi"
},
"start_location": {
"lat": 35.4675602,
"lng": -97.5164276
},
"end_location": {
"lat": 34.0522342,
"lng": -118.2436849
},
"start_address": "Oklahoma City, OK, USA",
"end_address": "Los Angeles, CA, USA"
} ],
"copyrights": "Map data ©2010 Google, Sanborn",
"overview_polyline": {
"points": "a~l~Fjk~uOnzh#vlbBtc~#tsE`vnApw{A`dw#~w\\|tNtqf#l{Yd_Fblh#rxo#b}#xxSfytAblk#xxaBeJxlcBb~t#zbh#jc|Bx}C`rv#rw|#rlhA~dVzeo#vrSnc}Axf]fjz#xfFbw~#dz{A~d{A|zOxbrBbdUvpo#`cFp~xBc`Hk#nurDznmFfwMbwz#bbl#lq~#loPpxq#bw_#v|{CbtY~jGqeMb{iF|n\\~mbDzeVh_Wr|Efc\\x`Ij{kE}mAb~uF{cNd}xBjp]fulBiwJpgg#|kHntyArpb#bijCk_Kv~eGyqTj_|#`uV`k|DcsNdwxAott#r}q#_gc#nu`CnvHx`k#dse#j|p#zpiAp|gEicy#`omFvaErfo#igQxnlApqGze~AsyRzrjAb__#ftyB}pIlo_BflmA~yQftNboWzoAlzp#mz`#|}_#fda#jakEitAn{fB_a]lexClshBtmqAdmY_hLxiZd~XtaBndgC",
"levels": "BBBAAAAABAABAAAAAABBAAABBAAAABBAAABABAAABABBAABAABAAAABABABABBABAABB"
},
"warnings": [ ],
"waypoint_order": [ 0, 1 ],
"bounds": {
"southwest": {
"lat": 34.0523600,
"lng": -118.2435600
},
"northeast": {
"lat": 41.8781100,
"lng": -87.6297900
}
}
} ]
}
Then parse the JSON returned to grab the duration.text and display it on your page.
You may have to comply with terms of service in order to use this API so make sure you read up on googles requirements and how they affect the use of the service.

Resources