當前位置: 首頁>>代碼示例>>Java>>正文


Java NameGender類代碼示例

本文整理匯總了Java中com.github.irobson.jgenderize.model.NameGender的典型用法代碼示例。如果您正苦於以下問題:Java NameGender類的具體用法?Java NameGender怎麽用?Java NameGender使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NameGender類屬於com.github.irobson.jgenderize.model包,在下文中一共展示了NameGender類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getGenders

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
public List<NameGender> getGenders(String[] names, Locale locale) {
    if (names.length == 0) {
        return Collections.emptyList();
    }

    WebTarget target = client.target(GENDERIZE_IO_API_URL);
    for (int i = 0; i < names.length; i++) {
        target = target.queryParam(String.format("name[%d]", i), names[i]);
    }
    if (locale != null) {
        target = target.queryParam("country_id", locale.getCountry());
        target = target.queryParam("language_id", locale.getLanguage());
    }
    if (apiKey != null) {
        target = target.queryParam("apikey", apiKey);
    }
    Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON_TYPE);

    return builder.get(NAME_GENDER_LIST_TYPE);
}
 
開發者ID:irobson,項目名稱:jgenderize,代碼行數:21,代碼來源:DefaultGenderize.java

示例2: testGetMultiNameGenderByLocalization

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
@Test
public void testGetMultiNameGenderByLocalization() {
    Genderize api = GenderizeIoAPI.create();
    List<NameGender> genders = api.getGenders(new String[]{"Robson", "Gilmar", "Marlise"}, new Locale("pt", "BR"));
    Assert.assertEquals(3, genders.size());
    Assert.assertTrue(genders.get(0).isMale());
    Assert.assertTrue(genders.get(1).isMale());
    Assert.assertTrue(genders.get(2).isFemale());
}
 
開發者ID:irobson,項目名稱:jgenderize,代碼行數:10,代碼來源:GenderizeIoAPITest.java

示例3: testGetMultiNameGender

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
@Test
public void testGetMultiNameGender() {
    Genderize api = GenderizeIoAPI.create();
    List<NameGender> genders = api.getGenders("Robson", "John", "Anna");
    Assert.assertEquals(3, genders.size());
    Assert.assertTrue(genders.get(0).isMale());
    Assert.assertTrue(genders.get(1).isMale());
    Assert.assertTrue(genders.get(2).isFemale());
}
 
開發者ID:irobson,項目名稱:jgenderize,代碼行數:10,代碼來源:GenderizeIoAPITest.java

示例4: getGender

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
public NameGender getGender(String name, Locale locale) {
    return getGenders(new String[]{name}, locale).get(0);
}
 
開發者ID:irobson,項目名稱:jgenderize,代碼行數:4,代碼來源:DefaultGenderize.java

示例5: testNullGender

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
@Test
public void testNullGender() {
    NameGender name = new NameGender();
    name.setGender("null");
    Assert.assertEquals(Gender.NULL, name.getGenderType());
}
 
開發者ID:irobson,項目名稱:jgenderize,代碼行數:7,代碼來源:GenderTest.java

示例6: testFemaleGender

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
@Test
public void testFemaleGender() {
    NameGender name = new NameGender();
    name.setGender("female");
    Assert.assertEquals(Gender.FEMALE, name.getGenderType());
}
 
開發者ID:irobson,項目名稱:jgenderize,代碼行數:7,代碼來源:GenderTest.java

示例7: testMaleGender

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
@Test
public void testMaleGender() {
    NameGender name = new NameGender();
    name.setGender("male");
    Assert.assertEquals(Gender.MALE, name.getGenderType());
}
 
開發者ID:irobson,項目名稱:jgenderize,代碼行數:7,代碼來源:GenderTest.java

示例8: testGetSingleNameGender

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
@Test
public void testGetSingleNameGender() {
    Genderize api = GenderizeIoAPI.create();
    NameGender gender = api.getGender("Kim");
    Assert.assertTrue(gender.isFemale());
}
 
開發者ID:irobson,項目名稱:jgenderize,代碼行數:7,代碼來源:GenderizeIoAPITest.java

示例9: testGetSingleNameGenderByLocalization

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
@Test
public void testGetSingleNameGenderByLocalization() {
    Genderize api = GenderizeIoAPI.create();
    NameGender gender = api.getGender("Kim", new Locale("da", "DK"));
    Assert.assertTrue(gender.isMale());
}
 
開發者ID:irobson,項目名稱:jgenderize,代碼行數:7,代碼來源:GenderizeIoAPITest.java

示例10: testGetNoNames

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
@Test
public void testGetNoNames() {
    List<NameGender> genders = GenderizeIoAPI.create().getGenders();
    Assert.assertEquals(0, genders.size());
}
 
開發者ID:irobson,項目名稱:jgenderize,代碼行數:6,代碼來源:GenderizeIoAPITest.java

示例11: testGetSingleNameGenderWithMultiMethod

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
@Test
public void testGetSingleNameGenderWithMultiMethod() {
    List<NameGender> genders = GenderizeIoAPI.create().getGenders("Robson");
    Assert.assertEquals(1, genders.size());
    Assert.assertTrue(genders.get(0).isMale());
}
 
開發者ID:irobson,項目名稱:jgenderize,代碼行數:7,代碼來源:GenderizeIoAPITest.java

示例12: testGetSingleNameUnknownGender

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
@Test
public void testGetSingleNameUnknownGender() {
    NameGender gender = GenderizeIoAPI.create().getGender("Thunderhorse");
    Assert.assertFalse(gender.isFemale());
    Assert.assertFalse(gender.isMale());
}
 
開發者ID:irobson,項目名稱:jgenderize,代碼行數:7,代碼來源:GenderizeIoAPITest.java

示例13: getCharacters

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
/**
 * Get the characters.
 *
 * @return an ArrayList of characters
 */
public ArrayList<Person> getCharacters() {
    ArrayList<Person> people = new ArrayList<Person>();
    Genderize api = GenderizeIoAPI.create();

    AbstractSequenceClassifier<CoreLabel> classifier;
    String fileContents;
    List<Triple<String, Integer, Integer>> list;
    HashSet<String> existingNames;

    try {
        classifier = CRFClassifier.getClassifier(CLASSIFIER);
        fileContents = IOUtils.slurpFile(filename);
        list = classifier.classifyToCharacterOffsets(fileContents);

        existingNames = new HashSet<String>();
        for (Triple<String, Integer, Integer> item : list) {
            if (item.first().equals("PERSON")) {
                String nameStr = fileContents.substring(item.second(),
                                                        item.third());
                nameStr = nameStr.replace("\n", " ")
                    .replace("\r", " ")
                    .replaceAll("\\s+", " ")
                    .trim();

                if (!existingNames.contains(nameStr)) {
                    existingNames.add(nameStr);

                    String[] names = nameStr.split(" ");
                    Person p = new Person();
                    p.setFirstname(names[0]);
                    if (names.length > 1) {
                        p.setLastname(names[1]);
                    }

                    NameGender gender = api.getGender(p.getFirstname());
                    if (gender.getGender() != null) {
                        p.setGender(gender.isMale() ? male : female);
                    } else {
                        p.setGender(getRandomGender());
                    }

                    people.add(p);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return people;
}
 
開發者ID:kennanmeyer,項目名稱:SE-410-Project,代碼行數:57,代碼來源:PersonImporter.java

示例14: getGender

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
NameGender getGender(String name); 
開發者ID:irobson,項目名稱:jgenderize,代碼行數:2,代碼來源:Genderize.java

示例15: getGenders

import com.github.irobson.jgenderize.model.NameGender; //導入依賴的package包/類
List<NameGender> getGenders(String... names); 
開發者ID:irobson,項目名稱:jgenderize,代碼行數:2,代碼來源:Genderize.java


注:本文中的com.github.irobson.jgenderize.model.NameGender類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。