From 6c0e83135056c4703218eefb1ece8b34ab671d6e Mon Sep 17 00:00:00 2001 From: NamSor Date: Sun, 28 Jan 2024 10:30:42 +0100 Subject: [PATCH] updated to v2.0.29 --- pom.xml | 2 +- .../java/com/namsor/tools/NamSorTools.java | 148 +++++++++++++----- 2 files changed, 111 insertions(+), 39 deletions(-) diff --git a/pom.xml b/pom.xml index d821b5c..4001f20 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ ${project.groupId} namsor-sdk2 - 2.0.27 + 2.0.29 org.junit.jupiter diff --git a/src/main/java/com/namsor/tools/NamSorTools.java b/src/main/java/com/namsor/tools/NamSorTools.java index f717048..53af595 100644 --- a/src/main/java/com/namsor/tools/NamSorTools.java +++ b/src/main/java/com/namsor/tools/NamSorTools.java @@ -17,6 +17,7 @@ import com.namsor.sdk2.model.BatchFirstLastNameDiasporaedOut; import com.namsor.sdk2.model.BatchFirstLastNameGenderedOut; import com.namsor.sdk2.model.BatchFirstLastNameGeoIn; +import com.namsor.sdk2.model.BatchFirstLastNameGeoOut; import com.namsor.sdk2.model.BatchFirstLastNameGeoSubclassificationOut; import com.namsor.sdk2.model.BatchFirstLastNameGeoSubdivisionIn; import com.namsor.sdk2.model.BatchFirstLastNameIn; @@ -29,12 +30,14 @@ import com.namsor.sdk2.model.BatchNameGeoIn; import com.namsor.sdk2.model.BatchNameIn; import com.namsor.sdk2.model.BatchPersonalNameCastegroupOut; +import com.namsor.sdk2.model.BatchPersonalNameDiasporaedOut; import com.namsor.sdk2.model.BatchPersonalNameGenderedOut; import com.namsor.sdk2.model.BatchPersonalNameGeoIn; import com.namsor.sdk2.model.BatchPersonalNameGeoOut; import com.namsor.sdk2.model.BatchPersonalNameGeoSubclassificationOut; import com.namsor.sdk2.model.BatchPersonalNameGeoSubdivisionIn; import com.namsor.sdk2.model.BatchPersonalNameIn; +import com.namsor.sdk2.model.BatchPersonalNameOriginedOut; import com.namsor.sdk2.model.BatchPersonalNameParsedOut; import com.namsor.sdk2.model.BatchPersonalNameReligionedOut; import com.namsor.sdk2.model.BatchPersonalNameSubdivisionIn; @@ -44,6 +47,7 @@ import com.namsor.sdk2.model.FirstLastNameDiasporaedOut; import com.namsor.sdk2.model.FirstLastNameGenderedOut; import com.namsor.sdk2.model.FirstLastNameGeoIn; +import com.namsor.sdk2.model.FirstLastNameGeoOut; import com.namsor.sdk2.model.FirstLastNameGeoSubclassificationOut; import com.namsor.sdk2.model.FirstLastNameGeoSubdivisionIn; import com.namsor.sdk2.model.FirstLastNameIn; @@ -56,12 +60,14 @@ import com.namsor.sdk2.model.NameGeoIn; import com.namsor.sdk2.model.NameIn; import com.namsor.sdk2.model.PersonalNameCastegroupOut; +import com.namsor.sdk2.model.PersonalNameDiasporaedOut; import com.namsor.sdk2.model.PersonalNameGenderedOut; import com.namsor.sdk2.model.PersonalNameGeoIn; import com.namsor.sdk2.model.PersonalNameGeoOut; import com.namsor.sdk2.model.PersonalNameGeoSubclassificationOut; import com.namsor.sdk2.model.PersonalNameGeoSubdivisionIn; import com.namsor.sdk2.model.PersonalNameIn; +import com.namsor.sdk2.model.PersonalNameOriginedOut; import com.namsor.sdk2.model.PersonalNameParsedOut; import com.namsor.sdk2.model.PersonalNameReligionedOut; import com.namsor.sdk2.model.PersonalNameSubdivisionIn; @@ -788,16 +794,19 @@ private Map processDiaspora(List processOriginGeo(List names) throws ApiException, IOException { - List namesNoGeo = new ArrayList(); - for (FirstLastNameGeoIn name : names) { - FirstLastNameIn nameNoGeo = new FirstLastNameIn(); - nameNoGeo.setId(name.getId()); - nameNoGeo.setFirstName(name.getFirstName()); - nameNoGeo.setLastName(name.getLastName()); - namesNoGeo.add(nameNoGeo); + private Map processDiasporaFull(List names) throws ApiException, IOException { + Map result = new HashMap(); + BatchPersonalNameGeoIn body = new BatchPersonalNameGeoIn(); + body.setPersonalNames(names); + BatchPersonalNameDiasporaedOut origined = personalApi.diasporaFullBatch(body); + for (PersonalNameDiasporaedOut personalName : origined.getPersonalNames()) { + result.put(personalName.getId(), personalName); } - return processOrigin(namesNoGeo); + return result; + } + + private Map processOriginGeo(List names) throws ApiException, IOException { + return processOrigin(fnLnGeoToNoGeo(names)); } private Map processOrigin(List names) throws ApiException, IOException { @@ -811,6 +820,21 @@ private Map processOrigin(List processOriginFullGeo(List names) throws ApiException, IOException { + return processOriginFull(nameGeoToNoGeo(names)); + } + + private Map processOriginFull(List names) throws ApiException, IOException { + Map result = new HashMap(); + BatchPersonalNameIn body = new BatchPersonalNameIn(); + body.setPersonalNames(names); + BatchPersonalNameOriginedOut origined = personalApi.originFullBatch(body); + for (PersonalNameOriginedOut personalName : origined.getPersonalNames()) { + result.put(personalName.getId(), personalName); + } + return result; + } + private Map processGender(List names) throws ApiException, IOException { Map result = new HashMap(); BatchFirstLastNameIn body = new BatchFirstLastNameIn(); @@ -844,23 +868,48 @@ private Map processCountry(List name return result; } - private Map processCountryGeo(List names) throws ApiException, IOException { - Map result = new HashMap(); - BatchPersonalNameIn body = new BatchPersonalNameIn(); - List names_ = new ArrayList(); - for (PersonalNameGeoIn name : names) { - PersonalNameIn noGeo = new PersonalNameIn(); - noGeo.setId(name.getId()); - noGeo.setName(name.getName()); - names_.add(noGeo); - } - body.setPersonalNames(names_); - BatchPersonalNameGeoOut countried = personalApi.countryBatch(body); - for (PersonalNameGeoOut personalName : countried.getPersonalNames()) { + private Map processCountryFnLn(List names) throws ApiException, IOException { + Map result = new HashMap(); + BatchFirstLastNameIn body = new BatchFirstLastNameIn(); + body.setPersonalNames(names); + BatchFirstLastNameGeoOut countried = personalApi.countryFnLnBatch(body); + for (FirstLastNameGeoOut personalName : countried.getPersonalNames()) { result.put(personalName.getId(), personalName); } return result; } + + private static List fnLnGeoToNoGeo(List names) { + List namesNoGeo = new ArrayList(); + for (FirstLastNameGeoIn name : names) { + FirstLastNameIn nameNoGeo = new FirstLastNameIn(); + nameNoGeo.setId(name.getId()); + nameNoGeo.setFirstName(name.getFirstName()); + nameNoGeo.setLastName(name.getLastName()); + namesNoGeo.add(nameNoGeo); + } + return namesNoGeo; + } + + + private Map processCountryFnLnGeo(List names) throws ApiException, IOException { + return processCountryFnLn(fnLnGeoToNoGeo(names)); + } + + private static final List nameGeoToNoGeo(List names) { + List namesNoGeo = new ArrayList(); + for (PersonalNameGeoIn name : names) { + PersonalNameIn nameNoGeo = new PersonalNameIn(); + nameNoGeo.setId(name.getId()); + nameNoGeo.setName(name.getName()); + namesNoGeo.add(nameNoGeo); + } + return namesNoGeo; + } + + private Map processCountryGeo(List names) throws ApiException, IOException { + return processCountry(nameGeoToNoGeo(names)); + } private Map processReligionFull(List names) throws ApiException, IOException { Map result = new HashMap(); @@ -978,17 +1027,7 @@ private Map processNameTypeGeo(List processCountryAdapted(List names_) throws ApiException, IOException { - List names = new ArrayList(); - for (FirstLastNameIn name : names_) { - PersonalNameIn adapted = new PersonalNameIn(); - adapted.setId(name.getId()); - adapted.setName(name.getFirstName() + " " + name.getLastName()); - names.add(adapted); - } - return processCountry(names); - } + private Map processGenderFullGeo(List names) throws ApiException, IOException { Map result = new HashMap(); @@ -1065,7 +1104,7 @@ private void processData(String service, String[] outputHeaders, Writer writer, Map genders = processGender(new ArrayList(firstLastNamesIn.values())); append(writer, outputHeaders, firstLastNamesIn, genders, softwareNameAndVersion); } else if (service.equals(SERVICE_NAME_COUNTRY)) { - Map countrieds = processCountryAdapted(new ArrayList(firstLastNamesIn.values())); + Map countrieds = processCountryFnLn(new ArrayList(firstLastNamesIn.values())); append(writer, outputHeaders, firstLastNamesIn, countrieds, softwareNameAndVersion); } firstLastNamesIn.clear(); @@ -1074,6 +1113,9 @@ private void processData(String service, String[] outputHeaders, Writer writer, if (service.equals(SERVICE_NAME_ORIGIN)) { Map origins = processOriginGeo(new ArrayList(firstLastNamesGeoIn.values())); append(writer, outputHeaders, firstLastNamesGeoIn, origins, softwareNameAndVersion); + } else if (service.equals(SERVICE_NAME_COUNTRY)) { + Map countrieds = processCountryFnLnGeo(new ArrayList(firstLastNamesIn.values())); + append(writer, outputHeaders, firstLastNamesGeoIn, countrieds, softwareNameAndVersion); } else if (service.equals(SERVICE_NAME_GENDER)) { Map genders = processGenderGeo(new ArrayList(firstLastNamesGeoIn.values())); append(writer, outputHeaders, firstLastNamesGeoIn, genders, softwareNameAndVersion); @@ -1099,6 +1141,9 @@ private void processData(String service, String[] outputHeaders, Writer writer, } else if (service.equals(SERVICE_NAME_COUNTRY)) { Map countrieds = processCountry(new ArrayList(personalNamesIn.values())); append(writer, outputHeaders, personalNamesIn, countrieds, softwareNameAndVersion); + } else if (service.equals(SERVICE_NAME_ORIGIN)) { + Map origins = processOriginFull(new ArrayList(personalNamesIn.values())); + append(writer, outputHeaders, personalNamesIn, origins, softwareNameAndVersion); } else if (service.equals(SERVICE_NAME_TYPE)) { Map nameTypeds = processNameType(new ArrayList(personalNamesIn.values())); append(writer, outputHeaders, personalNamesIn, nameTypeds, softwareNameAndVersion); @@ -1115,6 +1160,12 @@ private void processData(String service, String[] outputHeaders, Writer writer, } else if (service.equals(SERVICE_NAME_COUNTRY)) { Map countrieds = processCountryGeo(new ArrayList(personalNamesGeoIn.values())); append(writer, outputHeaders, personalNamesGeoIn, countrieds, softwareNameAndVersion); + } else if (service.equals(SERVICE_NAME_ORIGIN)) { + Map origins = processOriginFullGeo(new ArrayList(personalNamesGeoIn.values())); + append(writer, outputHeaders, personalNamesGeoIn, origins, softwareNameAndVersion); + } else if (service.equals(SERVICE_NAME_DIASPORA)) { + Map diasporas = processDiasporaFull(new ArrayList(personalNamesGeoIn.values())); + append(writer, outputHeaders, personalNamesGeoIn, diasporas, softwareNameAndVersion); } else if (service.equals(SERVICE_NAME_TYPE)) { Map nameTypeds = processNameTypeGeo(new ArrayList(personalNamesGeoIn.values())); append(writer, outputHeaders, personalNamesGeoIn, nameTypeds, softwareNameAndVersion); @@ -1193,10 +1244,8 @@ private void append(Writer writer, String[] outputHeaders, Map input, Map output } else if (inputObj instanceof FirstLastNamePhoneNumberIn) { FirstLastNamePhoneNumberIn firstLastNamePhoneNumberIn = (FirstLastNamePhoneNumberIn) inputObj; writer.append(digest(firstLastNamePhoneNumberIn.getFirstName()) + separatorOut + digest(firstLastNamePhoneNumberIn.getLastName())+ separatorOut+ digest(firstLastNamePhoneNumberIn.getPhoneNumber())+ separatorOut); - // - } else { - throw new IllegalArgumentException("Serialization of " + inputObj.getClass().getName() + " not supported"); + throw new IllegalArgumentException("Serialization of input " + inputObj.getClass().getName() + " not supported"); } if (outputObj == null) { for (String outputHeader : outputHeaders) { @@ -1214,6 +1263,14 @@ private void append(Writer writer, String[] outputHeaders, Map input, Map output if( religionoption ) { appendReligionStat(writer, firstLastNameOriginedOut.getReligionStats(),firstLastNameOriginedOut.getReligionStatsAlt()); } + } else if (outputObj instanceof PersonalNameOriginedOut) { + PersonalNameOriginedOut personalNameOriginedOut = (PersonalNameOriginedOut) outputObj; + String scriptName = personalNameOriginedOut.getScript();//NamSorTools.computeScriptFirst(firstLastNameOriginedOut.getLastName()); + //"region","topRegion","subRegion" + writer.append(personalNameOriginedOut.getRegionOrigin() + separatorOut + personalNameOriginedOut.getTopRegionOrigin() + separatorOut + personalNameOriginedOut.getSubRegionOrigin() + separatorOut + personalNameOriginedOut.getCountryOrigin() + separatorOut + personalNameOriginedOut.getCountryOriginAlt() + separatorOut + personalNameOriginedOut.getProbabilityCalibrated() + separatorOut + personalNameOriginedOut.getProbabilityAltCalibrated() + separatorOut + personalNameOriginedOut.getScore() + separatorOut + toCSV(personalNameOriginedOut.getCountriesOriginTop()) + separatorOut + scriptName + separatorOut); + if( religionoption ) { + appendReligionStat(writer, personalNameOriginedOut.getReligionStats(),personalNameOriginedOut.getReligionStatsAlt()); + } } else if (outputObj instanceof ProperNounCategorizedOut) { ProperNounCategorizedOut properNounCategorizedOut = (ProperNounCategorizedOut) outputObj; String scriptName = properNounCategorizedOut.getScript();//NamSorTools.computeScriptFirst(properNounCategorizedOut.getName()); @@ -1225,6 +1282,13 @@ private void append(Writer writer, String[] outputHeaders, Map input, Map output if( religionoption ) { appendReligionStat(writer, firstLastNameDiasporaedOut.getReligionStats(),firstLastNameDiasporaedOut.getReligionStatsAlt()); } + } else if (outputObj instanceof PersonalNameDiasporaedOut) { + PersonalNameDiasporaedOut firstLastNameDiasporaedOut = (PersonalNameDiasporaedOut) outputObj; + String scriptName = firstLastNameDiasporaedOut.getScript();//NamSorTools.computeScriptFirst(firstLastNameDiasporaedOut.getLastName()); + writer.append(firstLastNameDiasporaedOut.getEthnicity() + separatorOut + firstLastNameDiasporaedOut.getEthnicityAlt() + separatorOut + firstLastNameDiasporaedOut.getProbabilityCalibrated() + separatorOut + firstLastNameDiasporaedOut.getProbabilityAltCalibrated() + separatorOut + firstLastNameDiasporaedOut.getScore() + separatorOut + toCSV(firstLastNameDiasporaedOut.getEthnicitiesTop()) + separatorOut + scriptName + separatorOut); + if( religionoption ) { + appendReligionStat(writer, firstLastNameDiasporaedOut.getReligionStats(),firstLastNameDiasporaedOut.getReligionStatsAlt()); + } } else if (outputObj instanceof FirstLastNameGeoSubclassificationOut) { FirstLastNameGeoSubclassificationOut firstLastNameGeoSubclassificationOut = (FirstLastNameGeoSubclassificationOut) outputObj; String scriptName = firstLastNameGeoSubclassificationOut.getScript();//NamSorTools.computeScriptFirst(firstLastNameDiasporaedOut.getLastName()); @@ -1257,6 +1321,14 @@ private void append(Writer writer, String[] outputHeaders, Map input, Map output PersonalNameGenderedOut personalNameGenderedOut = (PersonalNameGenderedOut) outputObj; String scriptName = personalNameGenderedOut.getScript();//NamSorTools.computeScriptFirst(personalNameGenderedOut.getName()); writer.append(personalNameGenderedOut.getLikelyGender().getValue() + separatorOut + personalNameGenderedOut.getScore() + separatorOut + personalNameGenderedOut.getProbabilityCalibrated() + separatorOut + personalNameGenderedOut.getGenderScale() + separatorOut + scriptName + separatorOut); + } else if (outputObj instanceof FirstLastNameGeoOut) { + FirstLastNameGeoOut personalNameGeoOut = (FirstLastNameGeoOut) outputObj; + String scriptName = personalNameGeoOut.getScript();//NamSorTools.computeScriptFirst(personalNameGeoOut.getName()); + //"region","topRegion","subRegion" + writer.append(personalNameGeoOut.getRegion() + separatorOut + personalNameGeoOut.getTopRegion() + separatorOut + personalNameGeoOut.getSubRegion() + separatorOut + personalNameGeoOut.getCountry() + separatorOut + personalNameGeoOut.getCountryAlt() + separatorOut + personalNameGeoOut.getProbabilityCalibrated() + separatorOut + personalNameGeoOut.getProbabilityAltCalibrated() + separatorOut +personalNameGeoOut.getScore() + separatorOut + toCSV(personalNameGeoOut.getCountriesTop()) + separatorOut + scriptName + separatorOut); + if( religionoption ) { + appendReligionStat(writer, personalNameGeoOut.getReligionStats(),personalNameGeoOut.getReligionStatsAlt()); + } } else if (outputObj instanceof PersonalNameGeoOut) { PersonalNameGeoOut personalNameGeoOut = (PersonalNameGeoOut) outputObj; String scriptName = personalNameGeoOut.getScript();//NamSorTools.computeScriptFirst(personalNameGeoOut.getName()); @@ -1287,7 +1359,7 @@ private void append(Writer writer, String[] outputHeaders, Map input, Map output + firstLastNamePhoneCodedOut.getScore() + separatorOut + scriptName); } else { - throw new IllegalArgumentException("Serialization of " + outputObj.getClass().getName() + " not supported"); + throw new IllegalArgumentException("Serialization of output " + outputObj.getClass().getName() + " not supported"); } writer.append(softwareNameAndVersion + separatorOut); writer.append((rowId++) + "\n");