best solutions to combine different geo web services results? - geolocation

I would like to call different geo webservice in order to get the data with the geo location. for example I would like to search restaurants in san francisco from google place api, yelp api.
let say i will get the following data.
google:
restaurant A, address A, latlng(x1,y1) ,restaurant B, address B, latlng(x2,y2)
yelp:
restaurant C, address C, latlng(x3,y3) ,restaurant B1, address B1, latlng(x2.1,y2.1)
the situation is restaurant B and B1 are actually the same. A and C are different. and I need to display in my app with A, B, C restaurants.
How can I identify the difference of the result based on the name, address and latlng?
my solution is
compare the name with string first, if 100% same then return.
compare the address with street number, street name, zipcode, if 100% same then return
compare the coordinate, if the distance((x1,y1),(x2,y2)) < 10m then return.
I would like to ask if any better solution?

Related

How to count cypher labels with specific condition?

I have a graph database with information about different companies and their subsidiaries. Now my task is to display the structure of the company. This I have achieved with d3 and vertical tree.
But additionally I have to write summary statistics about the company that is currently displayed. Companies can be chosen from a dropdown list which is fetching this data dynamically via AJAX call.
I have to write in the same HTML a short summary like :
Total amount of subsidiaries for CompanyA: 300
Companies in Corporate Havens : 45%
Companies in Tax havens 5%
My database consists of two nodes: Company and Country, and the country has label like CH and TH.
CREATE (:TH:Country{name:'Nauru', capital:'Yaren', lng:166.920867,lat:-0.5477})
WITH 1 as dummy MATCH (a:Company), (b:Country) WHERE a.name=‘CompanyA ' AND b.name='Netherlands' CREATE (a)-[:IS_REGISTERED]->(b)
So how can I find amount of subsidiaries of CompanyA that are registered in corporate and tax havens? And how to pass this info further to html
I found different cypher queries to query all the labels as well as apocalyptic.stats but this does not allow me to filter on mother company. I appreciate help.
The cypher is good because you write a query almost in natural language (the query below may be incorrect - did not check, but the idea is clear):
MATCH (motherCompany:Company {name: 'CompanyA'})-[:HAS_SUBSIDIARY]->(childCompany:Company)
WITH motherCompany,
childCompany
MATCH (childCompany)-[:IS_REGISTERED]->(country:Country)
WITH motherCompany,
collect(labels(country)) AS countriesLabels
WITH motherCompany,
countriesLabels,
size([countryLabels IN countriesLabels WHERE 'TH' IN countryLabels ]) AS inTaxHeaven
RETURN motherCompany,
size(countriesLabels) AS total,
inTaxHeaven,
size(countriesLabels) - inTaxHeaven AS inCorporateHeaven

How can I find ALL the records with max attribute across records in rails?

I have several records with several attributes (A, B, C, D).
I want to be able to find which record has the higher value for a given attribute, such as D.
Team.of_city(seller_lead.city).with_access_to(seller_lead.state).max_by{ |team| team.rank }
For example, The above code gives me only one city but there are multiple cities with the same maximum rank. How do I get them all?
I would solve this with a subquery in the database:
Team.where(rank: Team.maximum(:rank)).
of_city(seller_lead.city).
with_access_to(seller_lead.state)

Search four fields in YQL geo.places

We are currently using YQL to query geo data for towns and counties in the UK. At the moment, we can use the following query to find all towns named Boston:
select * from geo.places where text="boston" and placeTypeName="Town"
Demo
The issue is, that we would like to specify the county and country to generate more specific results. I have tried the following query, but it returns 0 results:
select * from geo.places where (text="boston" and placeTypeName="Town") and (text="lincolnshire" and placeTypeName="County")
Demo
How can I query 3 field types to return the results I need? Essentially, we would like to query the following fields:
text and placeTypeName="Town"
text and placeTypeName="County"
text and placeTypeName="Country"
This may be an option maybe:
https://developer.yahoo.com/blogs/ydnsevenblog/solving-location-based-services-needs-yahoo-other-technology-7952.html
As it mentions:
Turning text into a location
You can also turn a text (name) into a location using the following code:
yqlgeo.get('paris,fr',function(o){
alert(o.place.name+' ('+
o.place.centroid.latitude+','+
o.place.centroid.longitude+
')');
})
This wrapper call uses our Placemaker Service under the hood and automatically disambiguates for you. This means that Paris is Paris, France, and not Paris Hilton; London is London, England, and not Jack London.

Match nodes of variable depth

I have users who like different geographies (could be a country, state or city) and I want to match those users who like geographies in the same country.
For eg.
user A likes USA
user B likes USA
user C likes San Jose
user D likes France
then I want user A to be matched to users B and C.
What cypher query will get me the results? This is what I tried:
/** node id of user A is 0 **/
START u=node(0) MATCH (u:users) - [:likes] - (g1) - [:contains*0..5] - (g2) - [:likes] - (o:users) RETURN o;
This query is not working as expected. What would be a right syntax?
If I understood you correctly, something like this might work in your case. But pay attention - there might be certain issues in case of circular paths.
The main idea behind this is setting not only relationships but their directions as well.

Get introduced [linkedin] like

I am using neo4j with people and companies as nodes and friend_of/works_at relationship between these.
I would like to know how to implement a get introduced to a second degree connection that linked in uses. The idea is to get your second degree connections at the company you wish to apply. If there are these second degree connections, then you would like to know who among your 1st deg connections can introduce y*ou to these 2nd deg connections.
For this I'm trying this query :
START from = node:Nodes(startNode), company = node:Nodes(endNode)
MATCH from-[:FRIEND_OF]->f-[:FRIEND_OF]-fof-[:WORKS_AT]->company
WHERE not(fof = from) and not (from-[:FRIEND_OF]->fof)
RETURN distinct f.name, fof.name, company.name
But, this returns duplicate friend of friend names (fof.name), since the distinct is applied on all the parameters that are returned as a whole. It could be like I have friends X and Y who are both connected to Z who works at company C. This way, I get both X-Z-C and Y-Z-C. But, I want to apply distinct on Z, such that I get either X-Z-C or Y-Z-C or maybe a list/collection/aggregate of all friends that connect to Z. This could like ["X","Y"..]->Z How should I modify my query?
http://console.neo4j.org/?id=s1m14g
start joe=node:node_auto_index(name = "Joe")
match joe-[:knows]->friend-[:knows]->friend_of_friend
where not(joe-[:knows]-friend_of_friend)
return collect(friend.name), friend_of_friend.name

Resources