AI Powered Name API Introduction
Name API is an AI feature developed by Aspose. This is a modern approach, which provides you with numerous useful functions to process names.
Aspose.Email Cloud now supports Artificial Intelligence functionalities and below we are going to emphasize Name API features.
Name API supports:
How to setup Aspose.Email Cloud SDKs:
SDK setup .
How To Detect a Person’s Gender By Name
You can parse the name of a person and try determining the gender. The API result contains a list of hypotheses about a person’s gender. All hypotheses include score, so you can use the most scored version, which will be the first in a list.
How To Compare Names To Determine The Similarity
The AI feature of Aspose.Email Cloud API enables you to compare the names to find out if they belong to the same person or not. As a result of the comparison, the answer is the similarity score and the list of mismatches.
Aspose.Email Cloud is also capable of formatting a person’s name in a correct case and name order using options for formatting instructions. So based on the instructions provided, the name sequence and case format are adjusted.
C#
var result = await api . Ai . Name . FormatAsync (
new AiNameFormatRequest (
"Mr. John Michael Cane" ,
format : "%t%L%f%m" ));
Assert . AreEqual ( "Mr. Cane J. M." , result . Name );
Java
AiNameFormatted result = api . ai (). name (). format (
new AiNameFormatRequest ()
. name ( "Mr. John Michael Cane" )
. format ( "%t%L%f%m" ));
assert result . getName (). equals ( "Mr. Cane J. M." );
Python
result = api . ai . name . format (
models . AiNameFormatRequest (
'Mr. John Michael Cane' ,
format = '%t %L% f%m' ))
assert result . name == 'Mr. Cane J. M.'
Ruby
result = api . ai . name . format (
AiNameFormatRequest . new (
name : 'Mr. John Michael Cane' ,
format : '%t%L%f%m' ))
expect ( result . name ) . to eq 'Mr. Cane J. M.'
Typescript
const result = await api . ai . name . format (
new AiNameFormatRequest (
'Mr. John Michael Cane' ,
undefined ,
undefined ,
undefined ,
undefined ,
'%t%L%f%m' ));
expect ( result . name ). to . be . equal ( 'Mr. Cane J. M.' );
PHP
$result = api -> ai () -> name () -> format (
new AiNameFormatRequest (
"Mr. John Michael Cane" ,
null ,
null ,
null ,
null ,
"%t%L%f%m" ));
$this -> assertEquals ( "Mr. Cane J. M." , $result -> getName ());
How To Display Possible Alternatives For Name
The AI feature of API provides a unique feature to display the person’s name into a list of possible alternatives.
How To Guess Name Based On Initials
Get the most probable names for given starting characters. The feature is similar to the recipient field in email client software. You start typing the name and based on initials provided, the possible names are listed. Please take a look over the following example where possible names starting with “Dav ”.
How To Parse Name From Email Address
The API enables you to determine the name of the person through an email address. It tries to identify the Firstname and Lastname while parsing the given email address.
C#
const string address = "john-cane@gmail.com" ;
var result = await api . Ai . Name . ParseEmailAddressAsync (
new AiNameParseEmailAddressRequest ( address ));
var extractedValues = result . Value
. SelectMany ( value => value . Name )
. ToList ();
var givenName = extractedValues . First ( value => value . Category == "GivenName" );
var surName = extractedValues . First ( value => value . Category == "Surname" );
Assert . AreEqual ( "John" , givenName . Value );
Assert . AreEqual ( "Cane" , surName . Value );
Java
String address = "john-cane@gmail.com" ;
ListResponseOfAiNameExtracted result = api . ai (). name (). parseEmailAddress (
new AiNameParseEmailAddressRequest (). emailAddress ( address ));
String givenName = null ;
String surname = null ;
for ( AiNameExtracted extracted : result . getValue ()) {
for ( AiNameExtractedComponent component : extracted . getName ()) {
if ( component . getCategory (). equals ( "GivenName" )) {
givenName = component . getValue ();
}
if ( component . getCategory (). equals ( "Surname" )) {
surname = component . getValue ();
}
}
}
assert "John" . equals ( givenName );
assert "Cane" . equals ( surname );
Python
address = 'john-cane@gmail.com'
result = api . ai . name . parse_email_address (
models . AiNameParseEmailAddressRequest ( address ))
names = ( extracted . name for extracted in result . value )
extracted_values = list ( functools . reduce ( lambda a , b : a + b , names ))
given_name = next (( x for x in extracted_values if x . category == 'GivenName' ))
surname = next (( x for x in extracted_values if x . category == 'Surname' ))
assert given_name . value == 'John'
assert surname . value == 'Cane'
Ruby
address = 'john-cane@gmail.com'
result = api . ai . name . parse_email_address (
AiNameParseEmailAddressRequest . new (
email_address : address ))
extracted_values = result . value
. map ( & :name )
. reduce ( :+ )
given_name = extracted_values . find do | item |
item . category == 'GivenName'
end
surname = extracted_values . find do | item |
item . category == 'Surname'
end
expect ( given_name . value ) . to eq 'John'
expect ( surname . value ) . to eq 'Cane'
Typescript
const result = await api . ai . name . parseEmailAddress (
new AiNameParseEmailAddressRequest ( 'john-cane@gmail.com' ));
const extractedValues = result . value
. map ( extracted => extracted . name )
. reduce (( accumulator , value ) => accumulator . concat ( value ));
const givenName = extractedValues . find (
extracted => extracted . category == 'GivenName' );
const surname = extractedValues . find (
extracted => extracted . category == 'Surname' );
expect ( givenName . value ). to . be . equal ( 'John' );
expect ( surname . value ). to . be . equal ( 'Cane' );
PHP
$address = "john-cane@gmail.com" ;
$result = api -> ai () -> name () -> parseEmailAddress (
new AiNameParseEmailAddressRequest ( $address ));
$extractedNames = array_map ( function ( $value ) {
return $value -> getName ();
}, $result -> getValue ());
$reduced = array_reduce ( $extractedNames , 'array_merge' , array ());
$givenName = array_values ( array_filter ( $reduced , function ( $value ) {
return $value -> getCategory () == "GivenName" ;
}))[ 0 ];
$surname = array_values ( array_filter ( $reduced , function ( $value ) {
return $value -> getCategory () == "Surname" ;
}))[ 0 ];
$this -> assertEquals ( "John" , $givenName -> getValue ());
$this -> assertEquals ( "Cane" , $surname -> getValue ());
More Tutorials
See more Aspose Email Tutorials: