private Verb cursorToVerb(Cursor cursor) { Verb verb = new Verb(); verb.setId(cursor.getLong(0)); verb.setNavnem(cursor.getString(2)); verb.setTranslation(cursor.getString(1)); verb.setNutid(cursor.getString(3)); verb.setDatid(cursor.getString(4)); verb.setFørnutid(cursor.getString(5)); verb.setFørdatid(cursor.getString(6)); verb.setBydem(cursor.getString(7)); verb.setBoj(cursor.getString(8)); return verb; }
private String getPermission(Noun noun, Verb verb) { String nounPerm = noun.getClass().getAnnotation(PermissionName.class).value(); String verbPerm = verb.getClass().getAnnotation(PermissionName.class).value(); if (nounPerm == null || verbPerm == null) throw new IllegalArgumentException( "The arguments you supplied do not specify permission values!"); return "core.permissions." + nounPerm + "." + verbPerm; }
Response doSend() throws IOException { connection.setRequestMethod(this.verb.name()); if (connectTimeout != null) { connection.setConnectTimeout(connectTimeout.intValue()); } if (readTimeout != null) { connection.setReadTimeout(readTimeout.intValue()); } if (boundary != null) { connection.setRequestProperty(CONTENT_TYPE, "multipart/form-data; boundary=" + boundary); } addHeaders(connection); if (verb.equals(Verb.PUT) || verb.equals(Verb.POST)) { addBody(connection, getByteBodyContents()); } return new Response(connection); }
Response doSend(RequestTuner tuner) throws IOException { connection.setRequestMethod(this.verb.name()); if (connectTimeout != null) { connection.setConnectTimeout(connectTimeout.intValue()); } if (readTimeout != null) { connection.setReadTimeout(readTimeout.intValue()); } tuner.tune(this); addHeaders(connection); if (verb.equals(Verb.PUT) || verb.equals(Verb.POST)) { addBody(connection, getByteBodyContents()); } return new Response(connection); }
private void verbArrayMaker() { verbs = new CharSequence[rfh.howManyRows(getContext())]; InputStream is = this.getResources().openRawResource(R.raw.verbs); String rivi = ""; InputStreamReader isr = new InputStreamReader(is); BufferedReader breader = new BufferedReader(isr); int i = 0; try { while (i < verbs.length) { rivi = breader.readLine(); verb.parseVerb(rivi); verbs[i] = verb.getInfinitive(); i++; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Override protected List<String> handleTabComplete( CommandSender sender, Command command, String alias, String[] args) { if (!sender.hasPermission(PERMISSION)) return Collections.emptyList(); // 0 - noun // 1 - noun autocomplete // 2 - verb // 3+ - not supported switch (args.length) { case 1: List<String> nounNames = new ArrayList<>(); for (Noun<?> noun : nouns) { String s1 = args[0].toLowerCase(); for (String s : noun.getNames()) { if (s.toLowerCase().startsWith(s1)) nounNames.add(s); } } return nounNames; case 2: Noun<?> nounFor = getNounFor(args[0]); if (nounFor == null) return Collections.emptyList(); return nounFor.getTabCompleteFor(args[1]); case 3: Noun<?> nounFor1 = getNounFor(args[0]); if (nounFor1 == null) return Collections.emptyList(); List<String> strings = new ArrayList<>(); for (Verb<? extends CPermissible> verb : nounFor1.getVerbs()) { String s1 = args[2].toLowerCase(); for (String s : verb.getNames()) { if (s.toLowerCase().startsWith(s1) && sender.hasPermission(getPermission(nounFor1, verb))) strings.add(s); } } return strings; default: return Collections.emptyList(); } }
private void setText() { Verb vnowVerb = list.get(posX); Verb vprevVerb = list.get(prevposX); Verb vnextVerb = list.get(nextposX); // setTextViews(nowVerb.getTranslation(), nowVerb.getNavnem(), nextVerb.getNavnem(), // prevVerb.getNavnem(), nowVerb.getDatid() + " " + nowVerb.getFørdatid() + " " + // nowVerb.getFørnutid()); nowVerb.setText(vnowVerb.getNavnem()); // bug // the next sceeen never shows the nextVerb it always shows the now verb nextVerb.setText(vnowVerb.getNavnem()); previousVerb.setText(vnowVerb.getNavnem()); englishVerb.setText(vnowVerb.getTranslation()); datidVerb.setText( "Datid : \n" + vnowVerb.getDatid() + "\n" + "Førnutid : \n" + vnowVerb.getFørnutid() + "\n" + "Førdatid : \n" + vnowVerb.getFørdatid()); }
protected <T extends CPermissible> void handleCommandUnspecific0( Noun<T> n, CommandSender sender, String[] args) throws CommandException { Verb<T> verb = null; for (Verb<T> verb1 : n.getVerbs()) { if (RandomUtils.contains(verb1.getNames(), args[2])) verb = verb1; } if (verb == null) throw new ArgumentRequirementException("The verb you specified is not valid!"); if (!sender.hasPermission(getPermission(n, verb))) throw new PermissionException("You do not have permission for this command!"); if (args.length - 3 < verb.getRequiredArguments()) throw new ArgumentRequirementException("You have not specified enough arguments!"); T target = n.get(args[1]); String[] strings = args.length <= 3 ? new String[] {} : Arrays.copyOfRange(args, 3, args.length); if (target == null && !verb.canAcceptNullTarget()) throw new ArgumentRequirementException("The target you specified is invalid!"); else if (target == null) strings = new String[] {args[1]}; verb.perform(sender, target, strings); Core.getPermissionsManager().save(); Core.getPermissionsManager().reloadPermissions(); if (Core.getNetworkManager() != null) Core.getNetworkManager().sendMassNetCommand(new PermissionsReloadNetCommand()); }
@RequestMapping( value = "", method = {RequestMethod.GET, RequestMethod.POST}) public void handleOAI( @RequestParam(value = VERB, defaultValue = EMPTY_STRING) String verbName, @RequestParam(value = IDENTIFIER, required = false) String identifier, @RequestParam(value = METADATA_PREFIX, defaultValue = EMPTY_STRING) String metadataPrefix, @RequestParam(value = FROM, required = false) String from, @RequestParam(value = UNTIL, required = false) String until, @RequestParam(value = SET, required = false) String set, @RequestParam(value = RESUMPTION_TOKEN, required = false) String resumptionToken, HttpServletRequest request, HttpServletResponse response) throws IOException, ConnectException, SolrServerException, TransformerConfigurationException { Verb theVerb; try { theVerb = Verb.valueOf(verbName); } catch (NullPointerException e) { theVerb = Verb.Identify; } catch (IllegalArgumentException e) { theVerb = Verb.Identify; } SolrQuery query = new SolrQuery(); query.set("echoParams", "all"); if (clientXsltHandler == null) { query.set("tr", String.format(xsltPath, verbName)); } query.set(VERB, verbName); query.set("requestStr", request.getRequestURL().toString()); query.setQuery("*:*"); Locale locale = Locale.getDefault(); for (String errorType : errorTypes) { addErrorQuery(errorType, query, locale); } switch (theVerb) { case ListIdentifiers: query.setFields(collectionIdField, datestampField, setIdField); // No Break, extra constraint adding to below query constraints case ListRecords: case GetRecord: query.set("collectionIdField", collectionIdField); query.set("datestampField", datestampField); for (String filter : filterQueries) { query.addFilterQuery(filter); } if (metadataPrefix != null) { query.set(METADATA_PREFIX, metadataPrefix); } break; } switch (theVerb) { case Identify: case ListMetadataFormats: query.setRows(0); break; case GetRecord: query.setRows(0); if (identifier != null) { query.set(IDENTIFIER, identifier); if (identifier.startsWith(identifierPrefix)) { String collStr = identifier.substring(identifierPrefix.length()); try { // This is to ensure that collId is a valid number query.setQuery(collectionIdField + ":" + Integer.parseInt(collStr)); query.setRows(1); } catch (NumberFormatException n) { // just skip setting query, solr will detect missing collection since there // are 0 rows } } } break; case ListIdentifiers: case ListRecords: query.set(IDENTIFIER, identifierPrefix); if (resumptionToken != null) { processResumptionToken(query, resumptionToken); from = query.get(FROM, null); until = query.get(UNTIL, null); } else { query.setRows(numResultsToDisplay); if (from != null) { query.set(FROM, from); } if (until != null) { query.set(UNTIL, until); } } if (datestampField != null) { processDateRange(query, from, until); } if (setIdField != null) { query.set("setIdField", setIdField); if (set != null) { if (setPrefix != null) { if (set.startsWith(setPrefix + ":")) { set = set.substring(setPrefix.length() + 1); } else { query.setRows(0); } } query.set(SET, set); try { // This is to ensure that set is a number query.addFilterQuery(setIdField + ":" + Integer.parseInt(set)); } catch (NumberFormatException n) { query.setRows(0); } } } if (setPrefix != null) { query.set("setPrefix", setPrefix); } break; case ListSets: query.set("setIdField", setIdField); query.set("setNameField", setNameField); query.set("setDescField", setDescField); query.set("setPrefix", setPrefix); query.set(RESUMPTION_TOKEN, resumptionToken); query.setFields(setIdField, setNameField, setDescField); query.setRows(numResultsToDisplay); for (String setQuery : setQueries) { query.addFilterQuery(setQuery); } if (resumptionToken != null) { processResumptionToken(query, resumptionToken); } break; } response.setContentType("text/xml"); ResponseParser parser = null; if (clientXsltHandler != null) { parser = clientXsltHandler.newParserInstance(response); } else { parser = new PassThroughSolrResponseParser(response); } System.out.println("Solr Query: " + query.toString()); CustomSolrQueryRequest req = new CustomSolrQueryRequest(query, parser); if (solrServer == null) { solrServer = new CommonsHttpSolrServer(solrServerUrl); } req.process(solrServer); }
/** * This class can be used to generate random movie titles. It uses it's own dictionary of words so * that the titles aren't <i>completely</i> unrealistic nonsense. */ public class RandomMovieTitleGenerator { private static final Determiner DETERMINER = Determiner.getInstance(); private static final Preposition PREPOSITION = Preposition.getInstance(); private static final Conjunction CONJUNCTION = Conjunction.getInstance(); private static final Noun NOUN = Noun.getInstance(); private static final Verb VERB = Verb.getInstance(); private static final Adjective ADJECTIVE = Adjective.getInstance(); private static final Word[][] TITLE_PATTERNS = { // 1-word {NOUN}, {ADJECTIVE}, // 2-word {DETERMINER, NOUN}, {NOUN, VERB}, {ADJECTIVE, NOUN}, {PREPOSITION, NOUN}, // 3-word {DETERMINER, NOUN, VERB}, {NOUN, CONJUNCTION, NOUN}, {DETERMINER, ADJECTIVE, NOUN}, {NOUN, PREPOSITION, NOUN}, // 4-word {DETERMINER, NOUN, CONJUNCTION, NOUN}, {DETERMINER, ADJECTIVE, NOUN, VERB}, {NOUN, CONJUNCTION, DETERMINER, NOUN}, {NOUN, PREPOSITION, DETERMINER, NOUN}, {NOUN, VERB, PREPOSITION, NOUN}, // 5-word {NOUN, CONJUNCTION, DETERMINER, ADJECTIVE, NOUN}, {DETERMINER, ADJECTIVE, NOUN, CONJUNCTION, NOUN}, {ADJECTIVE, NOUN, CONJUNCTION, ADJECTIVE, NOUN}, {NOUN, VERB, PREPOSITION, DETERMINER, NOUN}, {DETERMINER, NOUN, VERB, PREPOSITION, NOUN} }; public static String generateTitle() { // get random title pattern Random random = new Random(); int idx = random.nextInt(TITLE_PATTERNS.length); Word[] pattern = TITLE_PATTERNS[idx]; boolean nextWordVowel = false; boolean nextWordConsonant = false; String randomWord; // construct title with random words in the pattern List<String> titleWords = new ArrayList<>(); for (Word word : pattern) { if (nextWordVowel && word instanceof Noun) { randomWord = ((Noun) word).getRandomVowelNoun(); nextWordVowel = false; } else if (nextWordConsonant && word instanceof Noun) { randomWord = ((Noun) word).getRandomConsonantNoun(); nextWordConsonant = false; } else if (nextWordVowel && word instanceof Adjective) { randomWord = ((Adjective) word).getRandomVowelAdjective(); nextWordVowel = false; } else if (nextWordConsonant && word instanceof Adjective) { randomWord = ((Adjective) word).getRandomConsonantAdjective(); nextWordConsonant = false; } else { randomWord = word.getRandomWord(); // flag next word to start with consonant if this is "A" if (randomWord.equals("A")) { nextWordConsonant = true; } // flag next word to start with vowel if this is "An" else if (randomWord.equals("An")) { nextWordVowel = true; } } titleWords.add(randomWord); } return constructTitle(titleWords.toArray(new String[0])); } private static String constructTitle(String... words) { return StringUtils.join(words, " "); } /** Private classes */ private abstract static class Word { public abstract String getRandomWord(); } private static class Determiner extends Word { /* Words may be repeated to increase probability of being selected */ private static final String[] DETERMINERS = { "The", "The", "The", "The", "The", "A", "A", "An", "An", "My", "Our", "Their", "His", "Her", "The", "The" }; private static final Determiner _instance = new Determiner(); public static Determiner getInstance() { return _instance; } @Override public String getRandomWord() { Random random = new Random(); int idx = random.nextInt(DETERMINERS.length); return DETERMINERS[idx]; } } private static class Preposition extends Word { /* Words may be repeated to increase probability of being selected */ private static final String[] PREPOSITIONS = { "In", "At", "On", "Over", "After", "To", "Of", "Under", "From", "Through", "Before" }; private static final Preposition _instance = new Preposition(); public static Preposition getInstance() { return _instance; } @Override public String getRandomWord() { Random random = new Random(); int idx = random.nextInt(PREPOSITIONS.length); return PREPOSITIONS[idx]; } } private static class Conjunction extends Word { /* Words may be repeated to increase probability of being selected */ private static final String[] CONJUNCTIONS = { "for", "and", "and", "and", "but", "or", "and", "for", "and" }; private static final Conjunction _instance = new Conjunction(); public static Conjunction getInstance() { return _instance; } @Override public String getRandomWord() { Random random = new Random(); int idx = random.nextInt(CONJUNCTIONS.length); return CONJUNCTIONS[idx]; } } private static class Noun extends Word { private static final int CONSONANT_NOUNS_INDEX = 0; private static final int VOWEL_NOUNS_INDEX = 1; /* Words may be repeated to increase probability of being selected */ private static final String[][] NOUNS = { // starts with consonant { "Man", "Woman", "Kid", "Dog", "War", "House", "Family", "Race", "Person", "Water", "Fire", "Music", "Baker", "Cook", "Food", "Doctor", "Lawyer", "Number", "Singer", "Programmer", "Criminal", "Crime", "Cop", "Car", "Truck", "Boat", "River", "Ocean", "Country", "Smile", "Face", "Horse", "Penguin", "Pig", "Citizen", "Missiles", "Death", "Life", "Boss", "He", "She", "You", "They", "Michael", "Paul", "Peter", "Ruth", "John", "John", "Jane", "Revolution", "Magic", "Cloud", "Mother", "Father", "Desk", "Balloon", "Machine", "Politics", "Education", "Robot", "Zombie", "Monster", "Future", "Past", "Day", "Night", "School", "Dawn", "Stair", "Ladder", "Circus", "Clown", "Street", "Road", "City", "Sound", "Town", "Film", "Countryside", "Hotel", "Motorcycle", "Company", "Corporation", "Water", "Money", "Baseball", "Football", "Hockey", "Rope", "Tree", "Wind", "Insect", "Raven", "Bird", "Camel", "Smoke", "Spider", "Snake", "We", "Radio", "Shark", "Sea", "California", "Brooklyn", "Lake", "Sun", "Child", "Blood", "Fish", "Mountain", "Hill", "Mission", "Dad", "Mom", "Brother", "Sister", "Husband", "Wife", "Soul", "Art", "Glass", "Heart", "Time", "Moon", "Sun", "Star", "Planet", "Jet", "Sky", "Fence", "Neighborhood", "Door", "Window", "Opportunity", "Salesman", "Force" }, // starts with vowel { "Earth", "Idea", "It", "I", "Everything", "Eve", "Esther", "Alien", "Index", "Animal", "Elephant", "Albatross", "Ice", "Eagle", "Onyx", "Orange", "Apple", "Angel", "Angle", "Upstairs", "Understanding", "Overture", "Opening", "Ox", "Appointment", "Attitude", "Employee", "Eye", "Item", "Oregon", "Air", "Airplane", "Operation", "Office", "Uncle", "Aunt", "Ant", "Ape", "Ending", "End", "Exit", "Everyone", "Ether", "Airport", "Igloo", "Eskimo", "Iceland", "Alaska", "Italy", "Escape", "Immigrant", "Hour", "Advice", "Arrival" } }; private static final Noun _instance = new Noun(); public static Noun getInstance() { return _instance; } @Override public String getRandomWord() { Random random = new Random(); int nounsIdx = random.nextInt(2); if (nounsIdx == CONSONANT_NOUNS_INDEX) { return getRandomConsonantNoun(); } return getRandomVowelNoun(); } public String getRandomConsonantNoun() { Random random = new Random(); int idx = random.nextInt(NOUNS[CONSONANT_NOUNS_INDEX].length); return NOUNS[CONSONANT_NOUNS_INDEX][idx]; } public String getRandomVowelNoun() { Random random = new Random(); int idx = random.nextInt(NOUNS[VOWEL_NOUNS_INDEX].length); return NOUNS[VOWEL_NOUNS_INDEX][idx]; } } private static class Verb extends Word { private static final int PRESENT_VERBS_INDEX = 0; private static final int PAST_VERBS_INDEX = 1; /* Words may be repeated to increase probability of being selected */ private static final String[][] VERBS = { // present { "is", "Runs", "Goes", "Walks", "Says", "Touches", "Speaks", "Drifts", "Screams", "Wanders", "Hears", "Sees", "Believes", "Loves", "Stays", "Leaves", "Pays", "Leads", "Laughs", "Smiles", "Speaks", "Hurts", "Kills", "Saves", "Grows", "Drives", "Flies", "Swims", "Takes", "Loves", "is", "Writes", "Makes", "Cooks", "Sells", "Steals", "Falls", "Calls", "Travels", "is", "Loves", "is", "Sings", "Put", "Wonders", "Thinks", "Escapes", "Likes", "Likes", "Climbs", "Awakens", "Fight" }, // past { "Was", "Ran", "Went", "Walked", "Said", "Touched", "Heard", "Saw", "Believed", "Loved", "Stayed", "Left", "Paid", "Led", "Laughed", "Smiled", "Fell", "Won", "Battled", "Lost", "Spoke", "Hurt", "Killed", "Saved", "Grew", "Drove", "Flew", "Swam", "Took", "Wrote", "Made", "Cooked", "Sold", "Sang", "Stole", "Fell", "Called", "Traveled", "Put", "Thought", "Escaped", "Liked", "Quit", "Died", "Drifted", "Floated", "Shot", "Arrived", "Banned", "Answered", "Cut", "Froze", "Taught", "Shut" } }; private static final Verb _instance = new Verb(); public static Verb getInstance() { return _instance; } @Override public String getRandomWord() { Random random = new Random(); int nounsIdx = random.nextInt(2); if (nounsIdx == PRESENT_VERBS_INDEX) { return getRandomPresentVerb(); } return getRandomPastVerb(); } public String getRandomPresentVerb() { Random random = new Random(); int idx = random.nextInt(VERBS[PRESENT_VERBS_INDEX].length); return VERBS[PRESENT_VERBS_INDEX][idx]; } public String getRandomPastVerb() { Random random = new Random(); int idx = random.nextInt(VERBS[PAST_VERBS_INDEX].length); return VERBS[PAST_VERBS_INDEX][idx]; } } private static class Adjective extends Word { private static final int CONSONANT_ADJECTIVES_INDEX = 0; private static final int VOWEL_ADJECTIVES_INDEX = 1; /* Words may be repeated to increase probability of being selected */ private static final String[][] ADJECTIVES = { // starts with consonant { "Beautiful", "Weird", "Heavy", "Loud", "Light", "Crazy", "Mean", "Wonderful", "Magical", "Scary", "Horrible", "Stellar", "Broken", "Funny", "Narrow", "Dry", "Big", "Small", "Wide", "Black", "White", "Red", "Blue", "Green", "Yellow", "Gray", "Brown", "Purple", "Dark", "Sharp", "Bloody", "High", "Low", "Terrible", "Lovely", "Nice", "Wild", "Hard", "Long", "Short", "Frozen", "Sad", "Sweet", "Bitter", "Clear", "Quiet" }, // starts with vowel { "Incredile", "Amazing", "Easy", "Ugly", "Orange", "Inner", "Inside", "Impossible", "Indescribable", "Undisputed", "Inconvenient", "Unbroken", "Undefeated", "Adventurous", "Awesome", "Azure", "Ultimate", "Ultraviolet", "Unbearable", "Unbreakable", "Unchanged", "Uncomfortable", "Obtrusive", "Obtuse", "Obese", "Offensive", "Opaque", "Obnoxious", "Outstanding", "Open", "Accidental", "Official", "Omniscient", "Innocent", "Illegal" } }; private static final Adjective _instance = new Adjective(); public static Adjective getInstance() { return _instance; } @Override public String getRandomWord() { Random random = new Random(); int nounsIdx = random.nextInt(2); if (nounsIdx == CONSONANT_ADJECTIVES_INDEX) { return getRandomConsonantAdjective(); } return getRandomVowelAdjective(); } public String getRandomConsonantAdjective() { Random random = new Random(); int idx = random.nextInt(ADJECTIVES[CONSONANT_ADJECTIVES_INDEX].length); return ADJECTIVES[CONSONANT_ADJECTIVES_INDEX][idx]; } public String getRandomVowelAdjective() { Random random = new Random(); int idx = random.nextInt(ADJECTIVES[VOWEL_ADJECTIVES_INDEX].length); return ADJECTIVES[VOWEL_ADJECTIVES_INDEX][idx]; } } }