Changeset 30738 in osm for applications/editors/josm/plugins/trustosm/src/tools
- Timestamp:
- 2014-10-19T01:27:04+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/trustosm/src/tools/NameGenerator.java
r30737 r30738 8 8 /** 9 9 * This class is released under GNU general public license 10 * 10 * 11 11 * Description: This class generates random names from syllables, and provides programmer a 12 12 * simple way to set a group of rules for generator to avoid unpronounceable and bizarre names. 13 * 13 * 14 14 * SYLLABLE FILE REQUIREMENTS/FORMAT: 15 15 * 1) all syllables are separated by line break. … … 17 17 * 3) + and - characters are used to set rules, and using them in other way, may result in unpredictable results. 18 18 * 4) Empty lines are ignored. 19 * 19 * 20 20 * SYLLABLE CLASSIFICATION: 21 21 * Name is usually composed from 3 different class of syllables, which include prefix, middle part and suffix. … … 23 23 * To declare syllable as a suffix in the file, insert "+" as a first character of the line. 24 24 * everything else is read as a middle part. 25 * 25 * 26 26 * NUMBER OF SYLLABLES: 27 27 * Names may have any positive number of syllables. In case of 2 syllables, name will be composed from prefix and suffix. 28 28 * In case of 1 syllable, name will be chosen from amongst the prefixes. 29 29 * In case of 3 and more syllables, name will begin with prefix, is filled with middle parts and ended with suffix. 30 * 30 * 31 31 * ASSIGNING RULES: 32 32 * I included a way to set 4 kind of rules for every syllable. To add rules to the syllables, write them right after the 33 33 * syllable and SEPARATE WITH WHITESPACE. (example: "aad +v -c"). The order of rules is not important. 34 * 34 * 35 35 * RULES: 36 36 * 1) +v means that next syllable must definitely start with a vocal. … … 41 41 * Beware of creating logical mistakes, like providing only syllables ending with consonants, but expecting only vocals, which will be detected 42 42 * and RuntimeException will be thrown. 43 * 43 * 44 44 * TO START: 45 45 * Create a new NameGenerator object, provide the syllable file, and create names using compose() method. 46 * 46 * 47 47 * @author Joonas Vali, August 2009. 48 48 * … … 85 85 */ 86 86 public void refresh() throws IOException{ 87 88 FileReader input = null; 89 BufferedReader bufRead; 90 String line; 91 92 input = new FileReader(fileName); 93 94 bufRead = new BufferedReader(input); 95 line=""; 96 97 while(line != null){ 98 line = bufRead.readLine(); 99 if(line != null && !line.equals("")){ 100 if(line.charAt(0) == '-'){ 101 pre.add(line.substring(1).toLowerCase()); 102 } 103 else if(line.charAt(0) == '+'){ 104 sur.add(line.substring(1).toLowerCase()); 105 } 106 else{ 107 mid.add(line.toLowerCase()); 108 } 109 } 110 } 111 bufRead.close(); 112 } 113 114 private String upper(String s){ 87 try ( 88 FileReader input = new FileReader(fileName); 89 BufferedReader bufRead = new BufferedReader(input); 90 ) { 91 String line=""; 92 93 while (line != null) { 94 line = bufRead.readLine(); 95 if (line != null && !line.equals("")) { 96 if (line.charAt(0) == '-') { 97 pre.add(line.substring(1).toLowerCase()); 98 } else if (line.charAt(0) == '+') { 99 sur.add(line.substring(1).toLowerCase()); 100 } else{ 101 mid.add(line.toLowerCase()); 102 } 103 } 104 } 105 } 106 } 107 108 private String upper(String s) { 115 109 return s.substring(0,1).toUpperCase().concat(s.substring(1)); 116 110 } 117 111 118 private boolean containsConsFirst(ArrayList<String> array){ 119 for(String s: array){ 120 if(consonantFirst(s)) return true; 112 private boolean containsConsFirst(ArrayList<String> array) { 113 for (String s: array) { 114 if (consonantFirst(s)) return true; 121 115 } 122 116 return false;
Note:
See TracChangeset
for help on using the changeset viewer.