Projects >> knicker >>37bca2d29a573bd823e33ee61e9d6ac157226489

Chunk
Conflicting content
     *
    /**
     * Type format parameters used in some calls.
     * 
<<<<<<< HEAD
     * Note: The underscores will be replaced with dashes when using these
     *       values as parameters to the Wordnik API. For example,
     *       "verb_stem" becomes "verb-stem".
=======
     * You can pass a “*” as a single-character wild-card in the request, 
     * so “t*e” would match “the”.  The single-character wildcard will not
     * substitute a null character in its place, so “the*” will first match 
     * “they” not “the”.  You can pass multiple wildcards in a request.
     * 
     * This convenience method is equivalent to autocomplete(wordFragment, 0, 0, false, false);.
     *
     * @see http://docs.wordnik.com/api/methods#auto
     * @param wordFragment fragment to find matches for.
     * @throws KnickerException if wordFragment is null or if there are any errors.
     */
    public static SearchResult autocomplete(String wordFragment) throws KnickerException {
	return autocomplete(wordFragment, 0, 0, false, false);
    }


    /**
     * The autocomplete service takes a word fragment — that is, a few letters —
     * and returns words which start with that fragment. The results are based
     * on corpus frequency, not static word lists, so you have access to more
     * dynamic words in the language.
     *
     * You can pass a “*” as a single-character wild-card in the request,
     * so “t*e” would match “the”.  The single-character wildcard will not
     * substitute a null character in its place, so “the*” will first match
     * “they” not “the”.  You can pass multiple wildcards in a request.
     *
     * @see http://docs.wordnik.com/api/methods#auto
     * @param wordFragment fragment to find matches for.
     * @param limit limit the number of results. Zero will return all matches.
     * @param skip specify the starting index for the results returned. This
     * allows you to paginate through the matching values.
     * @param sortAlpha if true, data will be sorted by wordstring ascending. If
     * false, data will be sorted by frequency descending.
     * @param hasDef if true, only words with dictionary definitions will be returned.
     * @return search result object with results of the autocomplete.
     * @throws KnickerException if wordFragment is null or if there are any errors.
     */
    public static SearchResult autocomplete(String wordFragment, int limit, int skip, boolean sortAlpha, boolean hasDef)
	    throws KnickerException {
	if (wordFragment == null || wordFragment.isEmpty()) {
	    throw new KnickerException("Cannot look up an empty word fragment.");
	}

	Map params = new HashMap();
	if (limit > 0) {
	    params.put("limit", Integer.toString(limit));
	}
	if (skip > 0) {
	    params.put("skip", Integer.toString(skip));
	}
	if (sortAlpha) {
	    params.put("sortBy", "alpha");
	}
	if (hasDef) {
	    params.put("hasDictionaryDef", "true");
	}

	StringBuilder uri = new StringBuilder(SUGGEST_ENDPOINT);
	uri.append('/').append(wordFragment.trim());
	if (params.size() > 0) {
	    uri.append('?').append(Util.buildParamList(params));
	}

	return DTOBuilder.buildSearchResult(Util.doGet(uri.toString()));
    }


    /**
     * @see http://docs.wordnik.com/api/methods#random
	uri.append("/authenticate/").append(username);
	uri.append("?password=").append(password);

	try {
     * @param excludePartOfSpeech exclude words with specific parts of speech.
     * @param includePartOfSpeech include only words with specific parts of speech.
     * Fetch Wordnik’s Word-of-the-Day, including definitions and example sentences.
     *
     * @see http://docs.wordnik.com/api/methods#wotd
     * @return word of the day, with definitions and example sentences.
     * @throws KnickerException if there are any errors.
     */
    public static WordOfTheDay wordOfTheDay() throws KnickerException {
	return DTOBuilder.buildWordOfTheDay(Util.doGet(WOTD_ENDPOINT));
    }


    /**
     * Fetch a random word from the Wordnik corpus.
     *
     * @see http://docs.wordnik.com/api/methods#random
     * @param hasDictionaryDef only return words where there is a definition available.
     * @return random word.
     * @throws KnickerException if there are any errors.
     */
    public static Word randomWord(boolean hasDictionaryDef) throws KnickerException {
	StringBuilder uri = new StringBuilder(WORDS_ENDPOINT);
	uri.append("/randomWord");
	if (hasDictionaryDef) {
	    uri.append("?hasDictionaryDef=true");
	}

	return DTOBuilder.buildWord(Util.doGet(uri.toString()));
    }


    /**
     * Fetch multiple random words from the Wordnik corpus.
     *
     * This convenience method is equivalent to 
     * randomWords(null, null, 0, 0, 0, 0, 0, 0, 0, 0);.
     *
     * @see http://docs.wordnik.com/api/methods#random
     * @return list of random words.
     * @throws KnickerException if there are any errors.
     */
    public static List randomWords() throws KnickerException {
	return randomWords(null, null, 0, 0, 0, 0, 0, 0, 0, 0);
    }

    
    /**
     * Get random words conforming to the parameters provided.
	    auth = DTOBuilder.buildAuthenticationToken(Util.doGet(uri.toString()));
     * @param minCorpusCount match a specific corpus frequency in Wordnik's corpus.
     * @param maxCorpusCount match a specific corpus frequency in Wordnik's corpus.
     * @param minDictionaryCount match words .
     * @param maxDictionaryCount match words with a maximum number of definitions.
     * @param minLength match words with a minimum length.
     * @param maxLength match words with a maximum length.
     * @param skip skip a number of records.
     * @param limit limit the number of results. If this parameter is less than
     *        one, the default of 5 will be returned.
     * @return list of random words matching the parameters specified.
     * @throws KnickerException if there are any errors.
     */
    public static List randomWords(EnumSet includePartOfSpeech,
	    EnumSet excludePartOfSpeech, int minCorpusCount,
	    int maxCorpusCount, int minDictionaryCount, int maxDictionaryCount,
	    int minLength, int maxLength, int skip, int limit) throws
	    KnickerException {
	
	Map params = new HashMap();
	if (includePartOfSpeech != null && !includePartOfSpeech.isEmpty()) {
	    StringBuilder sb = new StringBuilder();
	    for (PartOfSpeech pos : includePartOfSpeech) {
		sb.append(pos.toString().trim().replaceAll("_", "-")).append(',');
	    }
	    if (sb.length() > 0) {
		sb.deleteCharAt(sb.length() - 1);
	    }
	    params.put("includePartOfSpeech", sb.toString());
	}
	if (excludePartOfSpeech != null && !excludePartOfSpeech.isEmpty()) {
	    StringBuilder sb = new StringBuilder();
	    for (PartOfSpeech pos : excludePartOfSpeech) {
		sb.append(pos.toString().trim().replaceAll("_", "-")).append(',');
	    }
	    if (sb.length() > 0) {
		sb.deleteCharAt(sb.length() - 1);
	    }
	    params.put("excludePartOfSpeech", sb.toString());
	}
	if (minCorpusCount > 0) {
	    params.put("minCorpusCount", Integer.toString(minCorpusCount));
	}
	if (maxCorpusCount > 0) {
	    params.put("maxCorpusCount", Integer.toString(maxCorpusCount));
	}
	if (minDictionaryCount > 0) {
	    params.put("minDictionaryCount", Integer.toString(minDictionaryCount));
	}
	if (maxDictionaryCount > 0) {
	    params.put("maxDictionaryCount", Integer.toString(maxDictionaryCount));
	}
	if (minLength > 0) {
	    params.put("minLength", Integer.toString(minLength));
	}
	if (maxLength > 0) {
	    params.put("maxLength", Integer.toString(maxLength));
	}
	if (skip > 0) {
	    params.put("skip", Integer.toString(skip));
	}
	if (limit > 0) {
	    params.put("limit", Integer.toString(limit));
	}


	StringBuilder uri = new StringBuilder(WORDS_ENDPOINT);
	uri.append("/randomWords");
	if (params.size() > 0) {
	    uri.append('?').append(Util.buildParamList(params));
	}

	return DTOBuilder.buildWords(Util.doGet(uri.toString()));

    }

    
    /**
     * Log in to Wordnik.
     *
     * Certain methods — currently, user accounts and list-related CRUD
     * operations — are only available to you if you pass a valid
     * authentication token.
     *
     * This method logs you in to Wordnik via the API and returns an instance of
     * AuthenticationToken which you can then use to make other
     * requests.
     *
     * @see http://docs.wordnik.com/api/methods#auth
     * @param username Wordnik username.
     * @param password Wordnik password for the user.
     * @return authentication token for the user.
     * @throws KnickerException if the username or password is null, or if there
     * are any errors.
     */
	} catch (Exception e) {
    public static AuthenticationToken authenticate(String username, String password) throws KnickerException {
	if (username == null || username.isEmpty()) {
	    throw new KnickerException("You must specify a username.");
	}
	if (password == null || password.isEmpty()) {
	    throw new KnickerException("You must specify a password.");
	}

	AuthenticationToken auth = null;

	StringBuilder uri = new StringBuilder(ACCOUNT_ENDPOINT);
	    throw new KnickerException("Unable to authenticate. Check your username and password.", e);
	}

	return auth;
    }


    /**
     * Check your API key usage by calling the apiTokenStatus
     * resource. This call does not count against your API usage.
     *
     * @see http://docs.wordnik.com/api/methods#usage
     * @return your current API usage information.
     * @throws KnickerException if there are any errors.
     */
    public static TokenStatus status() throws KnickerException {
	StringBuilder uri = new StringBuilder(ACCOUNT_ENDPOINT);
	uri.append("/apiTokenStatus");

	return DTOBuilder.buildTokenStatus(Util.doGet(uri.toString()));
    }
    

    /**
     * Fetch all of the authenticated user’s word lists.
     *
     * This method requires a valid authentication token, which can be obtained
     * by calling the authenticate method.
     *
     * @see http://docs.wordnik.com/api/methods#lists
     * @param token authentication token.
     * @return all of the user's word lists.
     * @throws KnickerException if the token is null, or if there are any errors.
     */
    public static List getLists(AuthenticationToken token) throws KnickerException {
	if (token == null) {
	    throw new KnickerException("Authentication token required.");
	}

	StringBuilder uri = new StringBuilder(WORDLISTS_ENDPOINT);
	
	return DTOBuilder.buildWordLists(Util.doGet(uri.toString(), token));
    }

    
    /**
     * Create a new list on behalf of the authenticated user.
     *
     * This method requires a valid authentication token, which can be obtained
     * by calling the authenticate method.
     *
     * @see http://docs.wordnik.com/api/methods#lists
     * @param token authentication token.
     * @param listName the name of the list to be created.
     * @param description a description of the list to be created.
     * @param type the type of list to be created.
     * @return the newly created word list.
     * @throws KnickerException if any parameters are null, or if there are any errors.
     */
    public static WordList createList(AuthenticationToken token, String listName, String description, ListType type) throws KnickerException {
	if (token == null) {
	    throw new KnickerException("Authentication token required.");
	}
	if (listName == null || listName.isEmpty()) {
	    throw new KnickerException("List name required.");
	}
	if (description == null || description.isEmpty()) {
	    throw new KnickerException("Description required.");
	}
	if (type == null) {
	    throw new KnickerException("List type required.");
	}

	/* The POST data should look like this:
	 *
	 
	    
	    test list
	    test
	    PUBLIC
	 
	 * 
	 */
	StringBuilder data = new StringBuilder("\n");
	data.append("\n");
	data.append("").append(description).append("\n");
	data.append("").append(listName).append("\n");
	data.append("").append(type.toString()).append("\n");
	data.append("");

	return DTOBuilder.buildWordList(Util.doPost(WORDLISTS_ENDPOINT, data.toString(), token));
    }

    
    /**
     * Add a word to the given list, on behalf of the authenticated user.
     *
     * @see http://docs.wordnik.com/api/methods#lists
     * @param token authentication token.
     * @param permalinkId the permalink id of the list to add the word to.
     * @param word the word to add to the given list.
     * @throws KnickerException if any parameters are null, or if there are any errors.
     */
    public static void addWordToList(AuthenticationToken token, String permalinkId, String word) throws KnickerException {
	if (token == null) {
	    throw new KnickerException("Authentication token required.");
	}
	if (permalinkId == null || permalinkId.isEmpty()) {
	    throw new KnickerException("Parameter permalinkId required.");
	}
	if (word == null || word.isEmpty()) {
	    throw new KnickerException("Parameter word required.");
	}

	/*
	
	
	    
		hello
	    
	
	 */
	StringBuilder data = new StringBuilder("\n");
	data.append("\n");
	data.append("\n");
	data.append("").append(word).append("\n");
	data.append("\n");
	data.append("\n");

	StringBuilder uri = new StringBuilder(WORDLIST_ENDPOINT);
	uri.append("/").append(permalinkId).append("/words");

	Util.doPost(uri.toString(), data.toString(), token);
    }

    
    /**
     * Return all the words from the given list.
     *
     * This method requires a valid authentication token, which can be obtained
     * by calling the authenticate method.
     *
     * @see http://docs.wordnik.com/api/methods#lists
     * @param token authentication token.
     * @param permalinkId the permalink of the word list to get words from.
     * @return list of word list words.
     * @throws KnickerException if the token or permalinkId are null, or if there are any errors.
     */
    public static List getWordsFromList(AuthenticationToken token, String permalinkId) throws KnickerException {
	if (token == null) {
	    throw new KnickerException("Authentication token required.");
	}
	if (permalinkId == null || permalinkId.isEmpty()) {
	    throw new KnickerException("Parameter permalinkId required.");
	}

	StringBuilder uri = new StringBuilder(WORDLIST_ENDPOINT);
	uri.append("/").append(permalinkId).append("/words");

	return DTOBuilder.buildWordListWords(Util.doGet(uri.toString(), token));
    }

    
    /**
     * Delete the given word from the given list.
     *
     * @see http://docs.wordnik.com/api/methods#lists
     * @param token authentication token.
     * @param permalinkId the permalink of the word list to delete the word from.
     * @param word the word to delete from the list.
     * @throws KnickerException if any parameter is invalid, or if there are any errors.
>>>>>>> d5b0badb4a7c13aa267c85a32cc4f22745ed4f72
     */
    public static enum TypeFormat {
	ahd,
Solution content
/*
 * Knicker is Copyright 2010-2011 by Jeremy Brooks
 *
 * This file is part of Knicker.
 *
 * Knicker is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Knicker is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Knicker.  If not, see .
*/
package net.jeremybrooks.knicker;


/**
 * Base class for the Wordnik API classes.
 *
 * 

This class defines the enum constants that are needed by the API classes. * Use the AccountApi, WordApi, WordListApi, * and WordsApi classes to access Wordnik.

* * @author jeremyb */ public abstract class Knicker { // API endpoints protected static final String ACCOUNT_ENDPOINT = "https://api.wordnik.com/v4/account.xml"; protected static final String WORD_ENDPOINT = "http://api.wordnik.com/v4/word.xml"; protected static final String WORD_LIST_ENDPOINT = "http://api.wordnik.com/v4/wordList.xml"; protected static final String WORD_LISTS_ENDPOINT = "http://api.wordnik.com/v4/wordLists.xml"; protected static final String WORDS_ENDPOINT = "http://api.wordnik.com/v4/words.xml"; /** * Source dictionaries supported by the Wordnik API. */ public static enum SourceDictionary { ahd, century, cmu, macmillan, wiktionary, webster, wordnet } /** * Parts of speech supported by the Wordnik API. * * Note: The underscores will be replaced with dashes when using these * values as parameters to the Wordnik API. For example, * "noun_and_verb" becomes "noun-and-verb". */ public static enum PartOfSpeech { noun, verb, adjective, adverb, idiom, article, abbreviation, preposition, prefix, interjection, suffix, conjunction, adjective_and_adverb, noun_and_adjective, noun_and_verb_transitive, noun_and_verb, past_participle, imperative, noun_plural, proper_noun_plural, verb_intransitive, proper_noun, adjective_and_noun, imperative_and_past_participle, pronoun, verb_transitive, noun_and_verb_intransitive, adverb_and_preposition, proper_noun_posessive, noun_posessive } /** * Relationship types supported by the Wordnik API. * *
    *
  • synonym: words with very similar meanings (beautiful: pretty)
  • *
  • antonym: words with opposite meanings (beautiful: ugly)
  • *
  • form: words with the same stem (dog: dogs, dogged, doggish)
  • *
  • hyponym: a word that is more specific (‘chair’ is a hyponym of ‘furniture’)
  • *
  • variant: a different spelling for the same word: color and colour are variants
  • *
  • verb-stem: Pass in a verb like “running” and get the stem, which is “run.”
  • *
  • verb-form: Pass in “run” and find different verb forms, like “running”, “ran”, and “runs.”
  • *
  • cross-reference: a related word; (bobcat: lynx)
  • *
  • same-context: Shows relationships between words which are often used in the same manner. For instance “cheeseburger” and “pizza” are often used the same way. Both also taste great.
  • *
* * Note: The underscores will be replaced with dashes when using these * values as parameters to the Wordnik API. For example, * "verb_stem" becomes "verb-stem". */ public static enum RelationshipType { synonym, antonym, form, hyponym, variant, verb_stem, verb_form, cross_reference, same_context } /** * List types supported by Wordnik. */ public static enum ListType { PUBLIC, PRIVATE } }
File
Knicker.java
Developer's decision
Manual
Kind of conflict
Comment
Method declaration
Chunk
Conflicting content
	}
	if (minCorpusCount > 0) {
	desc
    }

<<<<<<< HEAD
=======
	params.put("query", query);

	if (includePartOfSpeech != null && !includePartOfSpeech.isEmpty()) {
	    StringBuilder sb = new StringBuilder();
	    for (PartOfSpeech pos : includePartOfSpeech) {
		sb.append(pos.toString().trim().replaceAll("_", "-")).append(',');
	    }
	    if (sb.length() > 0) {
		sb.deleteCharAt(sb.length() - 1);
	    }
	    params.put("includePartOfSpeech", sb.toString());
	}
	if (excludePartOfSpeech != null && !excludePartOfSpeech.isEmpty()) {
	    StringBuilder sb = new StringBuilder();
	    for (PartOfSpeech pos : excludePartOfSpeech) {
		sb.append(pos.toString().trim().replaceAll("_", "-")).append(',');
	    }
	    if (sb.length() > 0) {
		sb.deleteCharAt(sb.length() - 1);
	    }
	    params.put("excludePartOfSpeech", sb.toString());
	    params.put("minCorpusCount", Integer.toString(minCorpusCount));
	}
	if (maxCorpusCount > 0) {
	    params.put("maxCorpusCount", Integer.toString(maxCorpusCount));
	}
	if (minDictionaryCount > 0) {
	    params.put("minDictionaryCount", Integer.toString(minDictionaryCount));
	}
	if (maxDictionaryCount > 0) {
	    params.put("maxDictionaryCount", Integer.toString(maxDictionaryCount));
	}
	if (minLength > 0) {
	    params.put("minLength", Integer.toString(minLength));
	}
	if (maxLength > 0) {
	    params.put("maxLength", Integer.toString(maxLength));
	}
	if (skip > 0) {
	    params.put("skip", Integer.toString(skip));
	}
	if (limit > 0) {
	    params.put("limit", Integer.toString(limit));
	}

	StringBuilder uri = new StringBuilder(WORDS_ENDPOINT);
	uri.append("/search");
	if (params.size() > 0) {
	    uri.append('?').append(Util.buildParamList(params));
	}

	return DTOBuilder.buildWordFrequency(Util.doGet(uri.toString()));
    }
>>>>>>> d5b0badb4a7c13aa267c85a32cc4f22745ed4f72
}
Solution content
    }
}
/*
 * Knicker is Copyright 2010-2011 by Jeremy Brooks
 *
 * This file is part of Knicker.
 *
 * Knicker is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Knicker is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Knicker.  If not, see .
*/
package net.jeremybrooks.knicker;


/**
 * Base class for the Wordnik API classes.
 *
 * 

This class defines the enum constants that are needed by the API classes. * Use the AccountApi, WordApi, WordListApi, * and WordsApi classes to access Wordnik.

* * @author jeremyb */ public abstract class Knicker { // API endpoints protected static final String ACCOUNT_ENDPOINT = "https://api.wordnik.com/v4/account.xml"; protected static final String WORD_ENDPOINT = "http://api.wordnik.com/v4/word.xml"; protected static final String WORD_LIST_ENDPOINT = "http://api.wordnik.com/v4/wordList.xml"; protected static final String WORD_LISTS_ENDPOINT = "http://api.wordnik.com/v4/wordLists.xml"; protected static final String WORDS_ENDPOINT = "http://api.wordnik.com/v4/words.xml"; /** * Source dictionaries supported by the Wordnik API. */ public static enum SourceDictionary { ahd, century, cmu, macmillan, wiktionary, webster, wordnet } /** * Parts of speech supported by the Wordnik API. * * Note: The underscores will be replaced with dashes when using these * values as parameters to the Wordnik API. For example, * "noun_and_verb" becomes "noun-and-verb". */ public static enum PartOfSpeech { noun, verb, adjective, adverb, idiom, article, abbreviation, preposition, prefix, interjection, suffix, conjunction, adjective_and_adverb, noun_and_adjective, noun_and_verb_transitive, noun_and_verb, past_participle, imperative, noun_plural, proper_noun_plural, verb_intransitive, proper_noun, adjective_and_noun, imperative_and_past_participle, pronoun, verb_transitive, noun_and_verb_intransitive, adverb_and_preposition, proper_noun_posessive, noun_posessive } /** * Relationship types supported by the Wordnik API. * *
    *
  • synonym: words with very similar meanings (beautiful: pretty)
  • *
  • antonym: words with opposite meanings (beautiful: ugly)
  • *
  • form: words with the same stem (dog: dogs, dogged, doggish)
  • *
  • hyponym: a word that is more specific (‘chair’ is a hyponym of ‘furniture’)
  • *
  • variant: a different spelling for the same word: color and colour are variants
  • *
  • verb-stem: Pass in a verb like “running” and get the stem, which is “run.”
  • *
  • verb-form: Pass in “run” and find different verb forms, like “running”, “ran”, and “runs.”
  • *
  • cross-reference: a related word; (bobcat: lynx)
  • *
  • same-context: Shows relationships between words which are often used in the same manner. For instance “cheeseburger” and “pizza” are often used the same way. Both also taste great.
  • *
* * Note: The underscores will be replaced with dashes when using these * values as parameters to the Wordnik API. For example, * "verb_stem" becomes "verb-stem". */ public static enum RelationshipType { synonym, antonym, form, hyponym, variant, verb_stem, verb_form, cross_reference, same_context } /** * List types supported by Wordnik. */ public static enum ListType { PUBLIC, PRIVATE
File
Knicker.java
Developer's decision
Manual
Kind of conflict
If statement
Method invocation
Return statement
Variable