@@ -93,7 +93,59 @@ describe('EmailApi', function() {
9393 expect ( factStartDate ) . toEqual ( startDate ) ;
9494 } ) ;
9595
96- it ( 'Parse business card images to VCard contact files #wip' , async function ( ) {
96+ it ( 'Name gender detection' , async function ( ) {
97+ var result = await api . aiNameGenderize ( new requests . AiNameGenderizeRequest ( 'John Cane' ) ) ;
98+ expect ( result . body . value . length ) . toBeGreaterThanOrEqual ( 1 ) ;
99+ expect ( result . body . value [ 0 ] . gender ) . toEqual ( 'Male' ) ;
100+ } ) ;
101+
102+ it ( 'Name formatting' , async function ( ) {
103+ var result = await api . aiNameFormat ( new requests . AiNameFormatRequest (
104+ 'Mr. John Michael Cane' , undefined , undefined , undefined , undefined , '%t%L%f%m' ) ) ;
105+ expect ( result . body . name ) . toEqual ( 'Mr. Cane J. M.' ) ;
106+ } ) ;
107+
108+ it ( 'Name match' , async function ( ) {
109+ var first = 'John Michael Cane' ;
110+ var second = 'Cane J.' ;
111+ var result = await api . aiNameMatch ( new requests . AiNameMatchRequest (
112+ first , second ) ) ;
113+ expect ( result . body . similarity ) . toBeGreaterThanOrEqual ( 0.5 ) ;
114+ } ) ;
115+
116+ it ( 'Name expand' , async function ( ) {
117+ var result = await api . aiNameExpand ( new requests . AiNameExpandRequest (
118+ 'Smith Bobby' ) ) ;
119+ var names = result . body . names
120+ . map ( weighted => weighted . name ) ;
121+ expect ( names ) . toContain ( 'Mr. Smith' ) ;
122+ expect ( names ) . toContain ( 'B. Smith' ) ;
123+ } ) ;
124+
125+ it ( 'Name complete' , async function ( ) {
126+ var prefix = 'Dav' ;
127+ var result = await api . aiNameComplete ( new requests . AiNameCompleteRequest (
128+ prefix ) ) ;
129+ var names = result . body . names
130+ . map ( weighted => prefix + weighted . name ) ;
131+ expect ( names ) . toContain ( 'David' ) ;
132+ expect ( names ) . toContain ( 'Davis' ) ;
133+ expect ( names ) . toContain ( 'Dave' ) ;
134+ } ) ;
135+
136+ it ( 'Parse name from email address' , async function ( ) {
137+ var result = await api . aiNameParseEmailAddress ( new requests . AiNameParseEmailAddressRequest (
138+ 'john-cane@gmail.com' ) ) ;
139+ var extractedValues = result . body . value
140+ . map ( extracted => extracted . name )
141+ . reduce ( ( accumulator , value ) => accumulator . concat ( value ) ) ;
142+ var givenName = extractedValues . find ( extracted => extracted . category == 'GivenName' ) ;
143+ var surname = extractedValues . find ( extracted => extracted . category == 'Surname' ) ;
144+ expect ( givenName . value ) . toEqual ( 'John' ) ;
145+ expect ( surname . value ) . toEqual ( 'Cane' ) ;
146+ } ) ;
147+
148+ it ( 'Parse business card images to VCard contact files' , async function ( ) {
97149 var imageData = fs . readFileSync ( 'tests/data/test_single_0001.png' ) ;
98150 var storageFileName = uuidv4 ( ) + '.png' ;
99151 // 1) Upload business card image to storage
@@ -123,6 +175,16 @@ describe('EmailApi', function() {
123175 expect ( contactProperties . body . internalProperties . length ) . toBeGreaterThanOrEqual ( 3 ) ;
124176 } ) ;
125177
178+ it ( 'Business card recognition without storage' , async function ( ) {
179+ var imageData = fs . readFileSync ( 'tests/data/test_single_0001.png' ) . toString ( 'base64' ) ;
180+ var result = await api . aiBcrParse ( new requests . AiBcrParseRequest (
181+ new models . AiBcrBase64Rq ( undefined , [ new models . AiBcrBase64Image ( true , imageData ) ] ) ) ) ;
182+ expect ( result . body . value . length ) . toEqual ( 1 ) ;
183+ var displayName = result . body . value [ 0 ] . internalProperties
184+ . find ( property => property . name == 'DISPLAYNAME' ) as models . PrimitiveObject ;
185+ expect ( displayName . value ) . toContain ( "Thomas" ) ;
186+ } ) ;
187+
126188 async function createCalendar ( startDate ? : Date ) :Promise < string > {
127189 var fileName = uuidv4 ( ) + '.ics' ;
128190 startDate = ( startDate == null ) ? getDate ( undefined , 1 ) : startDate ;
0 commit comments