I need to check gender by name. I have list of name in first form, such as: "Peter", "Anna" and etc. Its not very complicated, but application must return probability of gender,than name is not in first form, example "Peter" and "Petka" is equal. Maybe somebody knows good solution for NodeJS?
It is likely to fail quite often, and as pointed in comments, it may even offend some. That being said, there is an api that does exactly that : Genderize.io
It returns results like : {"name":"peter","gender":"male","probability":"0.99","count":796} You can also localize your query for more accuracy.
And their db is 177k names large, so it's probably your best bet.
EDIT :
To take the example you mention, here's what it returns for 'Petka' :
{
name: "petka",
gender: "female",
probability: "1.00",
count: 2
}
So I guess there's room for improvement.
or you can use name2gender.com with free 10000 api calls per month
response for 'peter':
{
"name" : "peter",
"gender" : "MALE",
"accuracy" : 98.53,
"samples" : 253705,
"country" : "WORLD",
"durationMs" : 0
}
more samples means more result of precision
You could also use https://veriocheck.com
They have API for name to gender lookup but they also provide name corrections along with it which we find more useful. So if the name was misspelled or incorrect, they provide corrections and then lookup correct gender.
It's better to use a professional API service like parser.name for this. You can post a name like Peter or Anna and you'll get back the gender of the names within milliseconds.
firstname: {
name: "Anna",
name_ascii: "Anna",
validated: true,
gender: "f",
gender_formatted: "female",
unisex: false,
gender_deviation: 0,
country_code: "US",
country_certainty: 31,
country_rank: 28,
alternative_countries: {
GB: 13,
PL: 8,
SE: 6
}
}
you can check https://genderapi.io
https://genderapi.io/api?name=peter;anna
{
"status": true,
"duration": "56ms",
"used_credits": 2,
"q": "peter;anna",
"names": [
{
"name": "peter",
"q": "peter",
"gender": "male",
"total_names": 4787,
"probability": 100
},
{
"name": "anna",
"q": "anna",
"gender": "female",
"total_names": 9609,
"probability": 100
}
]
}
Related
Thank you for your help.
I am scratching my head all day, I don't know I am in the right direction or not.
Problem :
I have a document [Doctor] which contains the reference [doctorSpecialities].
I have to GET ALL DOCTORS who have this id in there doctorSpecialities reference Array
Id : 5ef58dd048cdd203a0c07ba8
JSON Structure
{
"doctorSpecialities": [
"5f00cebc8bcdcd0660c12ce2",
"5ef58dd048cdd203a0c07ba8"
]
"_id": "5ef31ae80399ac05eb23e555",
"email": "signup#gmail.com",
"username": "signup#gmail.com",
"DOB": null,
"zip": null,
"phone": "12657334566",
"PMDC": "7658493",
"isVerified": false,
"aboutMe": "About Me",
"achievements": "Achievements",
"address": "padasdad",
"city": "Lahore",
"gender": "Male",
"managePractice": "Manage Practice",
"practiceGrowth": "Practice Growth",
"qualiflication": "Qualifcation",
"state": "eeeeeeee",
"workExperince": "Work Experince",
"doctorAvailability": [],
"doctorReviews": [],
"degreeCompletionYear": "2019-10-10",
"institute": "institute",
"practiceDate": "2020-10-10",
"services": "Dental"
},
Query tried
await Doctor.find({ doctorSpecialities : req.params.id})
await Doctor.find({ doctorSpecialities :{$in [ req.params.id}})
Specialty Collection
doctorCollection = Doctor.find();
doctorCollection.find({"doctorSpecialities": specialty.id})
This is how I did is it wrong?
I tried to user $Lookup but I don't know how to use it in this requirement
Please let me know if you need more information.
Thank you
If you have to get doctors details then you can use
db.collection.find({"doctorSpecialities":"5ef58dd048cdd203a0c07ba8"})
play
It returns all documents where doctorSpecialities field contains 5ef58dd048cdd203a0c07ba8
I am new to programming and I understand for loops, if/else statements and a bit of dictionaries. I don't mind coding things myself but I am having hard time figuring out the logic.
Problem statement - find the oldest person in the state with the lowest average age from this file.
I am able to iterate over the entire list and get all the entries printed out. But not sure how to find the oldest person with the lowest average... which is per state.
sample data:
[
{
"name": "xyz",
"state": "Connecticut",
"age": 95
},
{
"name": "abc",
"state": "Maine",
"age": 82
},
{
"name": "qwr",
"state": "Missouri",
"age": 56
},
{
"name": "qwer",
"state": "Maryland",
"age": 56
},
{
"name": "asdf",
"state": "Rhode Island",
"age": 17
},
]
Hm, could you clarify what you mean by "lowest average age"? Do you mean that you want to find 1.) the oldest person in the entire list, and also 2.) the state that has the lowest average age? In that case, you can do something like this:
def get_oldest_citizen(data):
return max(data, key=lambda citizen: citizen.age)
def get_state_with_youngest_average_age(data):
state_ages = {}
for citizen in data:
if citizen.state in state_ages:
state_ages[citizen.state] += [citizen.age]
else:
state_ages[citizen.state] = [citizen.age]
for state, ages in state_ages.items():
state_ages[state] = sum(ages) / len(ages)
return min(state_ages.values())
There's definitely a more concise and pythonic way to do the second one, but it gets the basic idea across -- basically just keep track of all citizens of a given state's ages, then take the average once you've recorded them all and find the youngest of those.
Edit 1: I realized now what you mean, that you want to find the oldest citizen in the state that has the lowest average age. In that case, all you have to do is use these two functions together, supplying the first with data you can find from the second.
You can rearrange your data by state. Then use min and lambda to find the lowest average state. then max and lambda to find theoldest person in that state.
data = [
{"name": "xyz", "state": "Connecticut", "age": 95},
{"name": "abc", "state": "Maine", "age": 82},
{"name": "qwr", "state": "Missouri", "age": 56},
{"name": "qwer", "state": "Maryland", "age": 22},
{"name": "asdf", "state": "Rhode Island", "age": 57},
{"name": "adam", "state": "Maryland", "age": 14},
]
from collections import defaultdict
data_by_state = defaultdict(list)
for record in data:
data_by_state[record["state"]].append(record)
lowest_avg_age_state = min(data_by_state, key=lambda state: sum([record["age"] for record in data_by_state[state]]) / len(data_by_state[state]))
print(f"{lowest_avg_age_state=}")
oldest_person_in_state = max(data_by_state[lowest_avg_age_state], key=lambda record: record["age"])
print(f"{oldest_person_in_state['name']=}")
OUTPUT
lowest_avg_age_state='Maryland'
oldest_person_in_state['name']='qwer'
I am currently working on a REST API, working with SequelizeJS and Express.
I'm used to Django Rest Framework and I'm trying to find a similar function :
I have a table User and a table PhoneNumber.
I want to be able to return a user in JSON, including the list of the primarykeys of its phone numbers like this :
{
"firstName": "John",
"lastName": "Doe",
"phoneNumbers": [23, 34, 54],
}
Is there a way to do this simply and efficiently in sequelize or do I have to write functions that transform the fields like :
"phoneNumbers": [
{ "id": 23, "number": "XXXXXXXXXX" },
{ "id": 34, "number": "XXXXXXXXXX" },
{ "id": 54, "number": "XXXXXXXXXX" }
]
into what I have above ?
Thank you,
Giltho
Sequelize finder-methods accept and option attribute that lets you define which properties of a model it should query for. See http://docs.sequelizejs.com/manual/tutorial/querying.html#attributes
That works for joins too:
User.all({
include: [
{ model: Phonenumber, attributes: ['id']}
]
})
.then(function(users) {
})
will execute
SELECT user.*, phonenumber.id FROM user INNER JOIN phonenumber ON ...
But to turn the phonenumbers into an array of integers [1,2,...] in your api response, you'd still have to map the ids manually into an array, otherwise you get an array of [{"id": 1}, {"id": 2},...].
But actually i recommend not to do that. An array of objects is the more future-proof option than an array of integers. Because your api-client don't need to change anything if you decide some day to expand the phonenumber object with additional attributes.
I have a Cloudant DB with the following structure:
{id: 1, resource:”john doe”, manager: “john smith”, amount: 13}
{id: 2, resource:”mary doe”, manager: “john smith”, amount: 3}
{id: 3, resource:”john smith”, manager: “peter doe”, amount: 10}
I needed a query to return the sum of amount, so I've built a query with emit(doc.manager, doc.amount) which returns
{"rows":[
{"key":"john smith","value":16},
{"key":"peter doe","value":10}]}
It is working like a charm. However I need the manager ID along with Manager name. The result I am looking for is:
{"rows":[
{"key":{"john smith",3},"value":16},
{"key":{"peter doe",null},"value":10}]}
How should I build a map view to search the parent ID?
Thanks,
Erik
Unfortunately I don't think there's a way to do exactly what you want in one query. Assuming you have the following three documents in your database:
{
"_id": "1",
"resource": "john doe",
"manager": "john smith",
"amount": 13
}
--
{
"_id": "2",
"resource": "mary doe",
"manager": "john smith",
"amount": 3
}
--
{
"_id": "3",
"resource": "john smith",
"manager": "peter doe",
"amount": 10
}
The closest thing to what you want would be the following map function (which uses a compound key) and a _sum reduce:
function(doc) {
emit([doc.manager, doc._id], doc.amount);
}
This would give you the following results with reduce=false:
{"total_rows":3,"offset":0,"rows":[
{"id":"1","key":["john smith","1"],"value":13},
{"id":"2","key":["john smith","2"],"value":3},
{"id":"3","key":["peter doe","3"],"value":10}
]}
With reduce=true and group_level=1, you essentially get the same results as what you already have:
{"rows":[
{"key":["john smith"],"value":16},
{"key":["peter doe"],"value":10}
]}
If you instead do reduce=true and group=true (exact grouping) then you get the following results:
{"rows":[
{"key":["john smith","1"],"value":13},
{"key":["john smith","2"],"value":3},
{"key":["peter doe","3"],"value":10}
]}
Each unique combination of the manager and _id field is summed, which unfortunately doesn't give you what you want. To accomplish what you want to accomplish, I think your best but would be to sum up the values after querying the database.
I'm new to ArangoDB and a growing fan already. Among many things we need to translate many-to-many relations into graphs, and query efficiently in there.
However I can't seem to reproduce the behaviour in NEIGHBORS as described in the cookbook
under "Using Edge Collections".
After I insert data and run:
FOR b IN books RETURN { book: b, authors: NEIGHBORS(books, written, b._id, 'inbound') }
[
{
"book" : {
"_id" : "books/10519631898915",
"_key" : "10519631898915",
"_rev" : "10519631898915",
"title" : "The beauty of JOINS"
},
"authors" : [ ]
}
]
Empty authors list! I tried this instead:
FOR b IN books RETURN { book: b, authors: NEIGHBORS(authors, written, b._id, 'inbound') }
[
{
"book" : {
"_id" : "books/10519631898915",
"_key" : "10519631898915",
"_rev" : "10519631898915",
"title" : "The beauty of JOINS"
},
"authors" : [
"authors/10519474612515",
"authors/10519475792163"
]
}
]
Which returns the _id list. None of those return what I need as in the cookbook, which is the expected edge/vertex structure.
(All has been tested in 2.6.9)
How is the use of NEIGHBORS intended and how do I get to my goal in pure AQL?
Is there a standard documentation of NEIGHBORS (and other graph AQL features) somewhere with description and type of each argument as well as return value?
Have you tried the includeData option for NEIGHBORS?
FOR b IN books RETURN { book: b, authors: NEIGHBORS(authors, written, b._id, 'inbound', [], {includeData: true}) }
That worked in my test.
It will be way more performant then PATHS on large datasets (PATHS computes much more irrelevant information)
Note: The empty array [] is used to define edges that should be followed only. With an empty array we follow all edges, but you could also follow special edges f.e. {label: "written"} instead of [].
Right, I found one solution:
FOR p IN PATHS(books, written, 'inbound')
RETURN p.destination
Result:
Warnings:
[1577], 'collection 'books' used as expression operand'
Result:
[
{
"_id": "books/10519631898915",
"_rev": "10519631898915",
"_key": "10519631898915",
"title": "The beauty of JOINS"
},
{
"_id": "authors/10519474612515",
"_rev": "10519474612515",
"_key": "10519474612515",
"name": {
"first": "John",
"last": "Doe"
}
},
{
"_id": "authors/10519475792163",
"_rev": "10519475792163",
"_key": "10519475792163",
"name": {
"first": "Maxima",
"last": "Musterfrau"
}
}
]
It gets the destination vertices at least, but it doesn't seem right since I get a warning and the source vertex is included as a destination.
Further elaboration and suggestions are very welcome.
UPDATE (2017): NEIGHBORS is no longer supported in AQL 3.x
Instead of
NEIGHBORS(books, written, b._id, 'inbound')
you could write a sub-query:
(FOR v IN 1..1 INBOUND b written RETURN v)