Identifying the gender and nationality of a list of names? - nlp

I have a list of names that I've extracted from articles, and I'm trying to guess demographic information about them (gender and nationality).
The list looks like:
Šefik Džaferović
Miloš Zeman
Abdel Fattah el-Sisi
სალომე ზურაბიშვილი
Michael D. Higgins
Maia Sandu
محمد السادس
Стево Пендаровски
with each list item including at least a first and second name.
Any advice on where to start?

You could get list of names from different countries; most countries will have records of their most common first names etc.
Once you have that data, you can set up a mapping between a name and the countries it is used in -- this will be a probability, as many names (most, probably) will occur in many countries, but will be more common in some than in others. For example, a lot of names of Turkish origin will be used in Germany, due to the sizable Turkish communities living there.
When you then get a name, you can consult that map, and get a likelihood for the nationality. If this is separate for first and last name, that might be more precise; but be aware that there is no absolute certainty.
With Gender it would work the same (helpfully, many list of baby names are split by gender); but there are also some ambiguous ones (Alex, Jan, Sam, Leslie, ...)

Related

Is there a logical function in excel to extract unique text values from a range of similar texts?

I am working on a dataset which has data (text) entries captured in different styles like we see in the table below in 1000's of rows:
**School Name **
Abirem school
Abirem sec School
Abirem Secondary school
Abirem second. School
Metropolitan elementary
Metropolitan Element.
Metropolitan ele
I need help to extract the unique data values within a group of similar entries regardless of the style it was entered. The output I want should look like we see below:
**School Name **
Abirem school
Metropolitan elementary
I have tried using the functions; EXACT, UNIQUE, MATCH and even XLOOKUP (with the wildcard option) but none of them gives me the output I want.
Is there a logical function that can be used?
This will prove to be tricky. Excel would not know wheather or not two different names that look similar are actually meant to be similar. Even for us humans it will become trivial. I mean; would School1 ABC be similar to School1 DEF or not? Without actually knowing geographical locations about these two schools these could well be two different schools with a similar first word in their names.
Either way, if you happen to be willing to accept this ambiguity you could make a match on the 1st word of each line here and return only those where they match first:
Formula in C1:
=LET(a,A1:A7,UNIQUE(XLOOKUP(TEXTSPLIT(a," ")&" *",a&" ",a,,2)))

Partial Index Match One Long Cell Value to Values from 3 Different Columns

Hi guys I have no idea how to do it at all since I probably don't get the logic behind building a formula for it so I'm going to ask here instead.
I'm administrating students' photos and have to collect them, and rename them to a consistent format. Basically, I have to do the following:
List the photo names by writing a .bat file using a simple command like dir /b *.jpg *jpeg *png *tiff >ClientList.txt
I create an Excel sheet to look for the students' names and student ID through a main database by performing Index Match
I Concatnate the results into a batch of Commands to be placed at Command Prompt to rename every photo at once
As of now, I am stuck at Step 2, doing them manually, because many students did not follow the guidelines and sent in their photos with sometimes only students IDs, sometimes First name, Last Name, sometimes Last Name, First Name; and sometimes a mix of name and student IDs. Also, students use names coming in different languages (Chinese and English)
As such, I want to have a way for Excel to search for the columns that contain English Names, Chinese Names and Student ID and return the closest match so that I don't have to identify them one by one.
I hope my question can be understood as I am not too sure how to explain it thoroughly.

String metric/similarity/measure: Identify same geographical locations (street addresses)

There is the issue when one retrieves address from some web service search, you get multiple results for the same actual place. For example the "Reverse Geocoding API" by Google, example from documentation:
"277 Bedford Avenue, Brooklyn, NY 11211, USA"
"Grand St/Bedford Av, Brooklyn, NY 11211, USA"
"Grand St/Bedford Av, Brooklyn, NY 11249, USA"
"Bedford Av/Grand St, Brooklyn, NY 11211, USA"
"Brooklyn, NY 11211, USA"
"Williamsburg, Brooklyn, NY, USA"
Suppose I need to choose only 1 and the most detailed one, so naive solution is to return the one with maximum characters.
But just before it, I want to verify all the options are actually describing the same place. The appropriate CS topic is String metric. How can I apply these algorithms on this task? Some problems why most of the metrics not applicable in this situation:
The order of the words not the same.
Not all the word necessary should appear, for example the descriptor "St." etc.
Thanks,
I would not simply compare strings here. Try analysing the address and identifying the components. For example, in
277 Bedford Avenue, Brooklyn, NY 11211, USA
You can see that:
Items separated by commas represent different entities, although items not separated might also be different concepts.
Earlier items represent smaller areas, later items are larger. You have a specific location on a street, the street, the city, the state, the country. The last item won't always be the country, but you can check it against a list of countries and only if it fails that consider other options. Similarly a list of state codes allows you to identify the NY.
A long sequence of digits close to the end is probably a zip code.
A short(ish) number (always watch out for suffixes like 'th' and 'st') at the beginning is probably a street number.
And so on in between. Then you have a semantic representation. It's safe to say that most addresses are written in this way. Forms asking you for your address generally have the same fields.
(Actually in the case of Google you don't even have to figure this out for yourself, they tell you what the components are. They also tell you what the most specific thing is.)
For the next one, similar things apply, but it's more complicated:
Grand St/Bedford Av, Brooklyn, NY 11211, USA
'Av' and 'St' need to be transformed into 'Avenue' and 'Street'. The meaning of the slash is not clear. We can treat it like a comma and consider "Grand St" and "Bedford Av" to be two different pieces of information. But from their position and the words "Street" and "Avenue", we know that the both represent the same kind of thing. So let's just say this place has two streets, and leave the exact meaning of that open. Perhaps it's a corner, perhaps the same street has two names.
Now when you compare the first two entities, you know that they have the same country, zip code, state, and city, so that's a good start but that's not very specific. The street of the first one is mentioned in the second one so that's good. The fact that the second one mentions an extra street is not really a problem. A problem would be two places with the streets (A, B) and (B, C). The street number is not there but that just means that the second location is less specific, so it's like the first is contained within the second.
You can safely conclude that the second, third, and fourth addresses are all the same. Only the zip code differs and that happens sometimes (zip codes are weird), there is too much that is the same elsewhere to dismiss a match. Also the zip codes are numerically close. If the country or state was different then they shouldn't match, but maybe create an alert so that a human is notified and can see if something is wrong. Also make sure that you have a proper dictionary normalising different names for the same place, e.g. NY == New York. For the fourth address, we know how to recognise it as having two streets, and we can disregard order (treat the streets as a set).
The fifth address is again just less information for smaller areas, so it contains the previous addresses. Note that if you only compare the third and fifth addresses they do not match. This shows that when you match the first two addresses you should 'merge' them and note that the two zip codes may be considered equivalent. Then later it will even be possible to say that "Brooklyn, NY 11211, USA" and "Brooklyn, NY 11249, USA" match.
The last address does not match any of the others. However this is only considering the plain string form. Google does actually mention Williamsburg for the first address.

Most Common Value within Sublists

I apologize in advance if this is unclear, I will try to explain everything as best I can! I am working with a data set in Google Sheets such that Column A is a list of student IDs and Column B is a list of student behaviors. It looks something like this:
A(ID) B(Behaviors)
12345 Talking
54321 Out of Seat
98765 Lying
12345 Talking
12345 Lying
98765 Lying
The list is data set is quite large because it contains recorded data from the entire school population over the course of the year, and as you can see the entire student population is pooled in one list. I am looking for a way to find each students (identified by their IDs) most commonly assigned behavior. For example, for the above data, student 12345 would have 'Talking' listed as their most common behavior and student 98765 would have 'Lying' listed as their most common behavior.
Ideally, I want to create a separate spreadsheet that looks something like this:
A(ID) B(Most Common Behavior)
12345 Talking
98765 Lying
54321 Out of Seat
Such that column A is a list of all the student's IDs and column B lists their most common behavior.
I found that I could use this formula:
=INDEX(Behaviors,MODE(MATCH(Behaviors,Behaviors,0)))
To pull out the most common value from the column containing scholar behaviors, but this formula gives me the most common behavior among the entire student population, so I am interested in modifying it so that the formula first looks at the student ID and then looks at the most common behavior within that sublist.
Please let me know if you require any further information. Thanks in advance for your help!
Are you familiar using PivotTables? You could just create a PivotTable with ID as a Row Label and Behavior as a column label and Value. Then it would just be a matter of copying/pasting those values and using a MAX formula to get the greatest behavior count.

Weighted search algorithm to find like contacts

I need to write an algorithm that returns the closest match for a contact based on the name and address entered by the user. Both of these are troubling, since there are so many ways to enter a company name and address, for instance:
Company A, 123 Any Street Suite 200, Anytown, AK 99012
Comp. A, 123 Any St., Suite 200, Anytown, AK 99012
CA, 123 Any Street Ste 200, Anytown, AK 99012
I have looked at doing a Levenshtein distance on the Name, but that doesn't seem a great tool, since they could abbreviate the name. I am looking for something that matches on the most information possible.
My initial attempt was to limit the results first by the first 5 digits of the postal code and then try to filter down to one based on other information, but there must be a more standard approach to getting this done. I am working in .NET but will look at any code you can provide to get an idea on how to accomplish this.
I don't exactly now how this is accomplished, but all major delivery companies (FedEx, USPS, UPS) seem to have a way of matching an address you input against their database and transforming it to a normalized form. As I've seen this happen on multiple websites (Amazon comes to mind), I am assuming that there is an API to this functionality, but I don't know where to look for it and whether it is suitable for your purposes.
Just a thought though.
EDIT: I found the USPS API
I have solved this problem with a combination of address normalization, Metaphone, and Levenshtein distance. You will need to separate the name from the address since they have different characteristics. Here are the steps you need to do:
1) Narrow down you list of matches by using the (first six characters of the) zip code. Basically you will need to calculate the Levenshtein distance of the two strings and select the ones that have a distance of 1 or 2 at the most. You can potentially precompute a table of zip codes and their "Levenshtein neighbors" if you really need to speed up the search.
http://en.wikipedia.org/wiki/Levenshtein_distance
2) Convert all the address abbreviations to a standard format using the list of official prefix and suffix abbreviations from the USPS. This will help make sure your results for the next step are more uniform:
https://www.usps.com/send/official-abbreviations.htm
3) Convert the address to a short code using the Methaphone algorithm. This will get rid of most common spelling mistakes. Just make sure that your implementation can eliminate all non word characters, pass numbers intact and handle multiple words (make sure each word is separated by a single space):
http://en.wikipedia.org/wiki/Metaphone
4) Once you have the Methaphone result of the compare the address strings using the Levenshtein distance. Calculate a percentage of change score by dividing the result by the number of characters in the longer string.
5) Repeat steps 3 and 4 but now use the names instead of the addresses.
6) Compute the score for each entry using this formula: (Weight for address * Address score) + (Weight for name * Name score). Pick your weights based on what is more important. I would start with .9 for the address (since the address is more specific) and .1 for the name but the weights may depend on your application. Pick the entry with the lowest score. If the score is too high (say over .15 you may declare that there are no matches).
I think filtering based on zip code first would be the easiest, as finding it is fairly unambiguous. From there you can probably extract the city and street. I'm not sure how you would go about finding the name, but it seems matching it against the address if you already have a database of (name, address) pairs is feasible.
Dun & Bradstreet do this. They charge money because it's really hard. There's no "standard" solution. It's mostly a painful choice between a service like D&B or roll your own.
As a start, I'd probably do a word-indexed search. That would mean two stages:
Offline stage: Generate an index of all the addresses by their keywords. For example, "Company", "A" and "123" would all become an keywords for the address you provided above. You could do some stemming, which would mean for words like "street" you'd also add a word "st" into its index.
Online stage: The user gives you a search query. Break down the search query into all its keywords, and find all possible matches of each keyword in the database. Tally the number of matched keywords on each address. Then sort the results by the number of matched keywords. This should be able to be done quite quickly if there aren't too many matches, as its just a few sorted list merges and increments, followed finally by a sort.
Given that you know the domain of your problem, you could specialise the algorithm to use knowledge about the domain - for example the zip code filtering mentioned before.
Also just to enable me to provide you with a better answer, are you using an SQL database at all? I ask because the way I would do it is I'd store the keyword index in the SQL database, and then the SQL query to search by keyword becomes quite easy, since the database does all the work.
Maybe instead of using Levenshtein for the name only, it could be useful when used with the entire string representation of a contact. For instance, the distance of your first example to the second is 7 and to the third 9. Considering the strings have lengths 54, 50 and 45, this seems to be a relatively useful and quite simple similarity measure.
This is what I would do. I am not aware of algorithms, so I just use what makes sense.
I am assuming that the person would provide name, street address, city name, state name, and zipcode.
If the zipcode is provided in 9 numbers, or has a hyphen, I would strip it down to 5 numbers. I would search the database for all of the addresses that has that zipcode.[query 1]
Then I would compare the state letter with the one from the database. If it's not a match, then I would tell that to the user. Same goes for the city name.
From what I understand, a street name is not in numbers, only the house on a street had numbers in it. Further more, the house number is usually at the beginning unless it is house or suite number.
So I would do regex to search for the numbers and the next space or comma next to it. Then find position of the first word that does not has a period(.) or ends in comma. I have part of the street name, so I could do a comparison against the rows fetched earlier, or I would change the query to have the street name LIKE %streetName%.
I am guessing the database has a beginning number and ending number of the house on a block. I would check against that street row to see if the provided street number is on that street.
By now you would know the correct data to show, and could look up in a different table as to which name is associated with that house number. I am not sure why you want to compare it. Only use for name comparing would be if you want to find people whose address was not provided. You can look here for comparing string ways Similar String algorithm
If you can reliably figure out general structure of each address (perhaps by the suggestions in the other answers), your best bet would be to run the data through a USPS-certified (meaning: the results are reliable, accurate, and conform to federal standards) address verification service.
#RyanDelucchi, it is a fun problem, but only once you've solved it. So, #SteveBering, I would recommend submitting your list of contacts to a list processing service which will flag duplicates based on the address -- according to USPS guidelines.
Since I work in the address verification field, I would suggest SmartyStreets (which I work for) since it will deliver the most value to your specific need -- however, there are a few CASS-Certified vendors who will do basically similar things.

Resources