There are 29 code examples for java.io.UnsupportedEncodingException.

The API names are highlighted below. You can use suckoo button to vote the code example(s) you like. The best code example will be ranked first next time. Thanks a lot for your feedback.

Project Name: codecover-instrumentation Package: org.codecover.instrumentation.measurement.parser

Source Code: CoverageLogParser.java (Click to view .java file)

Method Code:
vote
like

public void ReInit(java.io.InputStream stream,String encoding){
  try {
    jj_input_stream.ReInit(stream,encoding,1,1);
  }
 catch (  java.io.UnsupportedEncodingException e) {
    throw new RuntimeException(e);
  }
  token_source.ReInit(jj_input_stream);
  token=new Token();
  jj_ntk=-1;
  jj_gen=0;
  for (int i=0; i < 10; i++)   jj_la1[i]=-1;
  for (int i=0; i < jj_2_rtns.length; i++)   jj_2_rtns[i]=new JJCalls();
}
 

Project Name: jbidwatcher Package: com.jbidwatcher.app

Source Code: JBidProxy.java (Click to view .java file)

Method Code:
vote
like

public StringBuffer auctionsInCategory(String categoryName){
  String serviceURL=JConfig.queryConfiguration("tmp.service.url");
  try {
    String category=URLDecoder.decode(categoryName,"UTF-8");
    Category tab=Category.findFirstByName(category);
    List<AuctionEntry> auctions=AuctionEntry.findAllBy("category_id",tab.get("id"));
    XMLElement xauctions=new XMLElement("auctions");
    for (    AuctionEntry ae : auctions) {
      XMLElement child=ae.toXML();
      if (ae.getAuction().hasThumbnail()) {
        XMLElement thumbnail=new XMLElement("thumbnail");
        thumbnail.setContents(serviceURL + "/" + ae.getIdentifier()+ ".jpg");
        child.addChild(thumbnail);
      }
      XMLElement url=new XMLElement("url");
      url.setContents(ae.getBrowseableURL());
      child.addChild(url);
      xauctions.addChild(child);
    }
    StringBuffer sb=new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    sb.append("<!DOCTYPE auctions [\n" + "  <!ENTITY pound \"#\">\n" + "]>\n");
    sb.append(xauctions.toStringBuffer());
    return sb;
  }
 catch (  UnsupportedEncodingException crazy) {
    JConfig.log().logDebug("Couldn't decode the category name.");
  }
  return null;
}
 

Project Name: jbidwatcher Package: com.jbidwatcher.auction.server.ebay

Source Code: ebayLoginManager.java (Click to view .java file)

Method Code:
vote
like

private static URLConnection checkHTMLFollowRedirect(JHTML redirectPage,String lookFor,CookieJar cj){
  redirectPage.reset();
  JHTML.Form alertSuppressor=redirectPage.getFormWithInput("hidUrl");
  if (alertSuppressor != null) {
    if (alertSuppressor != null) {
      String url=redirectPage.getFormWithInput("hidUrl").getInputValue("hidUrl");
      return cj.connect(url);
    }
  }
  List<String> allURLs=redirectPage.getAllURLsOnPage(false);
  for (  String url : allURLs) {
    if (url.indexOf(lookFor) != -1) {
      url=url.replaceAll("&amp;","&");
      url=url.replaceAll("\n","");
      if (lookFor.equals("BidBin")) {
        int step=url.indexOf("BidBinInfo=");
        if (step != -1) {
          step+="BidBinInfo=".length();
          try {
            String encodedURL=URLEncoder.encode(url.substring(step),"UTF-8");
            url=url.substring(0,step) + encodedURL;
          }
 catch (          UnsupportedEncodingException ignored) {
            JConfig.log().logMessage("Failed to build a URL because of encoding transformation failure.");
          }
        }
      }
      return cj.connect(url);
    }
  }
  return null;
}
 

Project Name: jbidwatcher Package: com.jbidwatcher.ui

Source Code: JDropListener.java (Click to view .java file)

Method Code:
vote
like

private StringBuffer getInputStreamData(Transferable t,DataFlavor dtf,InputStream dropStream){
  BufferedReader br=useNewAPI(t,dtf);
  StringBuffer xferData;
  try {
    if (br == null) {
      if (JConfig.queryConfiguration("debug.uber","false").equals("true"))       JConfig.log().logDebug("Non-getReaderForText: " + dropStream);
      try {
        InputStreamReader isr=new InputStreamReader(dropStream,"utf-16le");
        xferData=getDataFromStream(dropStream);
        if (xferData != null) {
          return xferData;
        }
 else {
          br=new BufferedReader(isr);
        }
      }
 catch (      UnsupportedEncodingException uee) {
        JConfig.log().logDebug("Unicode encoding unsupported.");
        br=new BufferedReader(new InputStreamReader(dropStream));
      }
    }
    xferData=getDataFromReader(br);
  }
  finally {
    if (br != null)     try {
      br.close();
    }
 catch (    IOException ignored) {
    }
  }
  return xferData;
}
 

Project Name: jbidwatcher Package: com.jbidwatcher.util

Source Code: StringTools.java (Click to view .java file)

Method Code:
vote
like

public static String decode(String original,String charset){
  if (charset == null || charset.equalsIgnoreCase("UTF-8"))   return original;
  try {
    return new String(original.getBytes(),charset);
  }
 catch (  UnsupportedEncodingException ignore) {
    return original;
  }
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp

Source Code: NGramDB.java (Click to view .java file)

Method Code:
vote
like

public double get(String key){
  try {
    DatabaseEntry theKey=new DatabaseEntry(key.getBytes(encoding));
    DatabaseEntry theData=new DatabaseEntry();
    EntryBinding myBinding=TupleBinding.getPrimitiveBinding(Double.class);
    OperationStatus retVal=ngramsdb.get(null,theKey,theData,LockMode.DEFAULT);
    if (retVal == OperationStatus.SUCCESS) {
      Double value=(Double)myBinding.entryToObject(theData);
      if (value == Double.NaN)       throw new Error("NGram database says that " + key + " has a value of NaN");
      return value;
    }
 else {
      return 0.0;
    }
  }
 catch (  UnsupportedEncodingException e) {
    System.err.println(encoding + " is not a valid database encoding format");
    e.printStackTrace();
  }
catch (  DatabaseException e) {
    e.printStackTrace();
  }
  throw new Error("This code should never be reached");
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp

Source Code: SmoothedNGramDB.java (Click to view .java file)

Method Code:
vote
like

private void put(String key,double logProb,double backoff){
  try {
    if (Double.isInfinite(logProb) || Double.isNaN(logProb)) {
      System.err.println("WARNING: " + key + " has logProb=="+ logProb);
      System.exit(-1);
    }
    if (Double.isInfinite(backoff) || Double.isNaN(backoff)) {
      System.err.println("WARNING: " + key + " has backoff=="+ backoff);
      System.exit(-1);
    }
    SmoothedNGram value=new SmoothedNGram(logProb,backoff);
    DatabaseEntry theKey=new DatabaseEntry(key.getBytes(encoding));
    DatabaseEntry theData=new DatabaseEntry();
    binding.objectToEntry(value,theData);
    ngramsdb.put(null,theKey,theData);
  }
 catch (  UnsupportedEncodingException e) {
    System.err.println(encoding + " is not a valid database encoding format");
    e.printStackTrace();
  }
catch (  DatabaseException e) {
    e.printStackTrace();
  }
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt

Source Code: LexicalTranslationProbabilityDistribution.java (Click to view .java file)

Method Code:
vote
like

private double lookup(String key,Database probabilities){
  try {
    DatabaseEntry theKey=new DatabaseEntry(key.getBytes(encoding));
    DatabaseEntry theData=new DatabaseEntry();
    EntryBinding myBinding=TupleBinding.getPrimitiveBinding(Double.class);
    OperationStatus retVal=probabilities.get(null,theKey,theData,LockMode.DEFAULT);
    if (retVal == OperationStatus.SUCCESS) {
      Double value=(Double)myBinding.entryToObject(theData);
      return value;
    }
 else {
      return 0.0;
    }
  }
 catch (  UnsupportedEncodingException e) {
    System.err.println(encoding + " is not a valid database encoding format");
    e.printStackTrace();
  }
catch (  DatabaseException e) {
    e.printStackTrace();
  }
  return Double.NEGATIVE_INFINITY;
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.chiang2007

Source Code: LoglinearTranslationFeatures.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Convenience method to turn on logging during testing and debugging.
 * <p>
 * For normal uses, a logging configuration file probably be used instead of this method.
 * @param level Level at which to begin logging
 */
static void enableLogging(Level level){
  ConsoleHandler handler=new ConsoleHandler();
  try {
    handler.setEncoding("UTF-8");
  }
 catch (  SecurityException e) {
  }
catch (  UnsupportedEncodingException e) {
  }
  handler.setFormatter(new Formatter(){
    public String format(    LogRecord record){
      return "\tFEATURES: " + formatMessage(record) + "\n";
    }
  }
);
  handler.setLevel(Level.ALL);
  logger.addHandler(handler);
  logger.setLevel(level);
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.chiang2007

Source Code: RuleApplication.java (Click to view .java file)

Method Code:
vote
like

public static void main(String[] args) throws FileNotFoundException {
  CommandLineParser commandLine=new CommandLineParser();
  Option<String> lm_directory=commandLine.addStringOption('l',"language-model-db","DIRECTORY_NAME","language model database directory");
  commandLine.parse(args);
  try {
    System.setOut(new PrintStream(System.out,true,"UTF-8"));
    System.setErr(new PrintStream(System.err,true,"UTF-8"));
  }
 catch (  UnsupportedEncodingException e1) {
    System.err.println("UTF-8 is not a valid encoding; using system default encoding for System.out and System.err.");
  }
catch (  SecurityException e2) {
    System.err.println("Security manager is configured to disallow changes to System.out or System.err; using system default encoding.");
  }
  LanguageModel lm=new SmoothedNGramDB(commandLine.getValue(lm_directory),"UTF-8");
  Parser.setNGramOrder(3);
  System.out.println(elide("c g i"));
  System.out.println(elide("s f"));
  System.out.println(elide("c g " + ELIDE_STAR + " g i s f"));
  System.out.println(elide("<s> <s> c g " + ELIDE_STAR + " s f </s>"));
  System.out.println();
  String[] words={"c","g","i"};
  System.out.println(getLanguageModelScore(lm,words));
  double q=-1.0 * Math.log10(0.0);
  System.out.println(q);
  double qq=Math.log10(0.0);
  System.out.println(qq);
  double qqq=Math.log10(1.0);
  System.out.println(qqq);
  double qqqq=Math.log10(0.5);
  System.out.println(qqqq);
  double qqqqq=-1.0 * Math.log10(0.5);
  System.out.println(qqqqq);
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.chiang2007

Source Code: Translation.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Convenience method to turn on logging during testing and debugging.
 * <p>
 * For normal uses, a logging configuration file probably be used instead of this method.
 * @param level Level at which to begin logging
 */
static void enableLogging(Level level){
  ConsoleHandler handler=new ConsoleHandler();
  try {
    handler.setEncoding("UTF-8");
  }
 catch (  SecurityException e) {
  }
catch (  UnsupportedEncodingException e) {
  }
  handler.setFormatter(new Formatter(){
    public String format(    LogRecord record){
      return "\tTRANSLATION: " + formatMessage(record) + "\n";
    }
  }
);
  handler.setLevel(Level.ALL);
  logger.addHandler(handler);
  logger.setLevel(level);
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.chiang2007.common

Source Code: Translation.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Convenience method to turn on logging during testing and debugging.
 * <p>
 * For normal uses, a logging configuration file probably be used instead of this method.
 * @param level Level at which to begin logging
 */
static void enableLogging(Level level){
  ConsoleHandler handler=new ConsoleHandler();
  try {
    handler.setEncoding("UTF-8");
  }
 catch (  SecurityException e) {
  }
catch (  UnsupportedEncodingException e) {
  }
  handler.setFormatter(new Formatter(){
    public String format(    LogRecord record){
      return "\tTRANSLATION: " + formatMessage(record) + "\n";
    }
  }
);
  handler.setLevel(Level.ALL);
  logger.addHandler(handler);
  logger.setLevel(level);
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.chiang2007.common

Source Code: RuleApplication.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Convenience method to turn on logging during testing and debugging.
 * <p>
 * For normal uses, a logging configuration file probably be used instead of this method.
 * @param level Level at which to begin logging
 */
static void enableLogging(Level level){
  ConsoleHandler handler=new ConsoleHandler();
  try {
    handler.setEncoding("UTF-8");
  }
 catch (  SecurityException e) {
  }
catch (  UnsupportedEncodingException e) {
  }
  handler.setFormatter(new Formatter(){
    public String format(    LogRecord record){
      return "\tRULE-APP: " + formatMessage(record) + "\n";
    }
  }
);
  handler.setLevel(Level.ALL);
  logger.addHandler(handler);
  logger.setLevel(level);
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.chiang2007.cubepruning

Source Code: RuleApplication.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Convenience method to turn on logging during testing and debugging.
 * <p>
 * For normal uses, a logging configuration file probably be used instead of this method.
 * @param level Level at which to begin logging
 */
static void enableLogging(Level level){
  ConsoleHandler handler=new ConsoleHandler();
  try {
    handler.setEncoding("UTF-8");
  }
 catch (  SecurityException e) {
  }
catch (  UnsupportedEncodingException e) {
  }
  handler.setFormatter(new Formatter(){
    public String format(    LogRecord record){
      return "\tRULE-APP: " + formatMessage(record) + "\n";
    }
  }
);
  handler.setLevel(Level.ALL);
  logger.addHandler(handler);
  logger.setLevel(level);
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.chiang2007.cubepruning

Source Code: Translation.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Convenience method to turn on logging during testing and debugging.
 * <p>
 * For normal uses, a logging configuration file probably be used instead of this method.
 * @param level Level at which to begin logging
 */
static void enableLogging(Level level){
  ConsoleHandler handler=new ConsoleHandler();
  try {
    handler.setEncoding("UTF-8");
  }
 catch (  SecurityException e) {
  }
catch (  UnsupportedEncodingException e) {
  }
  handler.setFormatter(new Formatter(){
    public String format(    LogRecord record){
      return "\tTRANSLATION: " + formatMessage(record) + "\n";
    }
  }
);
  handler.setLevel(Level.ALL);
  logger.addHandler(handler);
  logger.setLevel(level);
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.chiang2007.intersection

Source Code: RuleApplication.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Convenience method to turn on logging during testing and debugging.
 * <p>
 * For normal uses, a logging configuration file probably be used instead of this method.
 * @param level Level at which to begin logging
 */
static void enableLogging(Level level){
  ConsoleHandler handler=new ConsoleHandler();
  try {
    handler.setEncoding("UTF-8");
  }
 catch (  SecurityException e) {
  }
catch (  UnsupportedEncodingException e) {
  }
  handler.setFormatter(new Formatter(){
    public String format(    LogRecord record){
      return "\tRULE-APP: " + formatMessage(record) + "\n";
    }
  }
);
  handler.setLevel(Level.ALL);
  logger.addHandler(handler);
  logger.setLevel(level);
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.chiang2007.intersection

Source Code: Translation.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Convenience method to turn on logging during testing and debugging.
 * <p>
 * For normal uses, a logging configuration file probably be used instead of this method.
 * @param level Level at which to begin logging
 */
static void enableLogging(Level level){
  ConsoleHandler handler=new ConsoleHandler();
  try {
    handler.setEncoding("UTF-8");
  }
 catch (  SecurityException e) {
  }
catch (  UnsupportedEncodingException e) {
  }
  handler.setFormatter(new Formatter(){
    public String format(    LogRecord record){
      return "\tTRANSLATION: " + formatMessage(record) + "\n";
    }
  }
);
  handler.setLevel(Level.ALL);
  logger.addHandler(handler);
  logger.setLevel(level);
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.chiang2007.rescoring

Source Code: Translation.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Convenience method to turn on logging during testing and debugging.
 * <p>
 * For normal uses, a logging configuration file probably be used instead of this method.
 * @param level Level at which to begin logging
 */
static void enableLogging(Level level){
  ConsoleHandler handler=new ConsoleHandler();
  try {
    handler.setEncoding("UTF-8");
  }
 catch (  SecurityException e) {
  }
catch (  UnsupportedEncodingException e) {
  }
  handler.setFormatter(new Formatter(){
    public String format(    LogRecord record){
      return "\tTRANSLATION: " + formatMessage(record) + "\n";
    }
  }
);
  handler.setLevel(Level.ALL);
  logger.addHandler(handler);
  logger.setLevel(level);
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.chiang2007.rescoring

Source Code: RuleApplication.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Convenience method to turn on logging during testing and debugging.
 * <p>
 * For normal uses, a logging configuration file probably be used instead of this method.
 * @param level Level at which to begin logging
 */
static void enableLogging(Level level){
  ConsoleHandler handler=new ConsoleHandler();
  try {
    handler.setEncoding("UTF-8");
  }
 catch (  SecurityException e) {
  }
catch (  UnsupportedEncodingException e) {
  }
  handler.setFormatter(new Formatter(){
    public String format(    LogRecord record){
      return "\tRULE-APP: " + formatMessage(record) + "\n";
    }
  }
);
  handler.setLevel(Level.ALL);
  logger.addHandler(handler);
  logger.setLevel(level);
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.tools

Source Code: CreateNGramDB.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Create a ngram probability database, given an ARPA backoff N-gram model file.
 * @param args command line arguments
 */
public static void main(String[] args){
  CommandLineParser commandLine=new CommandLineParser();
  Option<String> directory=commandLine.addStringOption('d',"db-directory","DIRECTORY_NAME","database directory");
  Option<String> encoding=commandLine.addStringOption('e',"encoding","ENCODING","UTF-8","database encoding");
  Option<String> ngram_file=commandLine.addStringOption('f',"ngram-file","FILE_NAME","ARPA N-gram model file");
  Option<Boolean> ngram_file_gz=commandLine.addBooleanOption("ngram-file-gzipped",false,"is the ngram file gzipped");
  commandLine.parse(args);
  NGramDB db=null;
  try {
    Scanner scanner;
    if (commandLine.getValue(ngram_file).endsWith(".gz") || commandLine.getValue(ngram_file_gz))     scanner=new Scanner(new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(commandLine.getValue(ngram_file))),commandLine.getValue(encoding))));
 else     scanner=new Scanner(new File(commandLine.getValue(ngram_file)),commandLine.getValue(encoding));
    db=new NGramDB(scanner,commandLine.getValue(directory),commandLine.getValue(encoding));
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
  }
catch (  UnsupportedEncodingException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
 finally {
    if (db != null) {
      db.close();
    }
  }
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.tools

Source Code: CreateLexProbDB.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Create a lexical translation probability database, given word pair count data.
 * @param args
 */
public static void main(String[] args){
  CommandLineParser commandLine=new CommandLineParser();
  Option<String> source_to_target_counts=commandLine.addStringOption('s',"source-to-target-counts","FILENAME","name of file containing source to target word pair counts");
  Option<String> target_to_source_counts=commandLine.addStringOption('t',"target-to-source-counts","FILENAME","name of file containing target to source word pair counts");
  Option<String> encoding=commandLine.addStringOption('e',"encoding","ENCODING","UTF-8","input file encoding");
  Option<Boolean> source_to_target_gz=commandLine.addBooleanOption("source-to-target-gzipped",false,"is the source to target word pair counts file gzipped");
  Option<Boolean> target_to_source_gz=commandLine.addBooleanOption("target-to-source-gzipped",false,"is the target to source word pair counts file gzipped");
  Option<String> dbDirectory=commandLine.addStringOption('d',"db-directory","DIRECTORY_NAME","database directory");
  commandLine.parse(args);
  LexicalTranslationProbabilityDistribution lexProbs=null;
  try {
    try {
      System.setOut(new PrintStream(System.out,true,commandLine.getValue(encoding)));
      System.setErr(new PrintStream(System.err,true,commandLine.getValue(encoding)));
    }
 catch (    UnsupportedEncodingException e1) {
      System.err.println(commandLine.getValue(encoding) + " is not a valid encoding; using system default encoding for System.out and System.err.");
    }
catch (    SecurityException e2) {
      System.err.println("Security manager is configured to disallow changes to System.out or System.err; using system default encoding.");
    }
    Scanner source_to_target;
    if (commandLine.getValue(source_to_target_counts).endsWith(".gz") || commandLine.getValue(source_to_target_gz))     source_to_target=new Scanner(new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(commandLine.getValue(source_to_target_counts))),commandLine.getValue(encoding))));
 else     source_to_target=new Scanner(new File(commandLine.getValue(source_to_target_counts)),commandLine.getValue(encoding));
    Scanner target_to_source;
    if (commandLine.getValue(target_to_source_counts).endsWith(".gz") || commandLine.getValue(target_to_source_gz))     target_to_source=new Scanner(new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(commandLine.getValue(target_to_source_counts))),commandLine.getValue(encoding))));
 else     target_to_source=new Scanner(new File(commandLine.getValue(target_to_source_counts)),commandLine.getValue(encoding));
    lexProbs=new LexicalTranslationProbabilityDistribution(source_to_target,target_to_source,commandLine.getValue(dbDirectory),commandLine.getValue(encoding));
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
  }
catch (  UnsupportedEncodingException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
 finally {
    if (lexProbs != null) {
      lexProbs.close();
    }
  }
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.tools

Source Code: CalculatePhrasePairLexProbs.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Calculates the actual lexical translation probability (in one direction only)
 * for each phrase pair using weighted averaging.
 * @param args
 */
public static void main(String[] args){
  CommandLineParser commandLine=new CommandLineParser();
  Option<String> input_file=commandLine.addStringOption('i',"input-file","ALIGNMENT_FILENAME","name of file containing phrase pairs and preliminary lexprob data");
  Option<Boolean> input_file_gz=commandLine.addBooleanOption("input-file-gzipped",false,"is the input file gzipped");
  Option<String> input_file_encoding=commandLine.addStringOption("input-encoding","INPUT_ENCODING","UTF-8","input file encoding");
  Option<String> output_file=commandLine.addStringOption('o',"output","OUTPUT_FILENAME","file where output will be written");
  Option<String> output_file_encoding=commandLine.addStringOption("output-encoding","OUTPUT_ENCODING","UTF-8","output file encoding");
  Option<Boolean> output_file_gz=commandLine.addBooleanOption("output-text-gzipped",false,"should the output file be gzipped");
  Option<String> input_delimiter_pattern=commandLine.addStringOption('d',"delimiter","PATTERN","\\s+:::\\s+","input file field delimiter pattern");
  Option<String> output_delimiter_pattern=commandLine.addStringOption("output-delimiter","STRING","  :::  ","input file field delimiter");
  commandLine.parse(args);
  Writer outputFile=null;
  try {
    Scanner input;
    if (commandLine.getValue(input_file).equals("-"))     input=new Scanner(System.in);
 else     if (commandLine.getValue(input_file).endsWith(".gz") || commandLine.getValue(input_file_gz))     input=new Scanner(new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(commandLine.getValue(input_file))),commandLine.getValue(input_file_encoding))));
 else     input=new Scanner(new File(commandLine.getValue(input_file)),commandLine.getValue(input_file_encoding));
    if (commandLine.getValue(output_file).endsWith(".gz") || commandLine.getValue(output_file_gz))     outputFile=new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(commandLine.getValue(output_file))),commandLine.getValue(output_file_encoding));
 else     outputFile=new OutputStreamWriter(new FileOutputStream(commandLine.getValue(output_file)),commandLine.getValue(output_file_encoding));
    String input_delimiter=commandLine.getValue(input_delimiter_pattern);
    String output_delimiter=commandLine.getValue(output_delimiter_pattern);
    calculate(input,input_delimiter,outputFile,output_delimiter);
    if (outputFile != null) {
      outputFile.flush();
      outputFile.close();
    }
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
  }
catch (  UnsupportedEncodingException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.tools

Source Code: RuleLookup.java (Click to view .java file)

Method Code:
vote
like

public static void main(String[] args){
  CommandLineParser commandLine=new CommandLineParser();
  Option<String> grammar_directory=commandLine.addStringOption('r',"grammar-rules-db","DIRECTORY_NAME","grammar rules database directory");
  Option<String> encoding=commandLine.addStringOption('e',"encoding","ENCODING","UTF-8","database encoding");
  commandLine.parse(args);
  try {
    System.setOut(new PrintStream(System.out,true,commandLine.getValue(encoding)));
    System.setErr(new PrintStream(System.err,true,commandLine.getValue(encoding)));
  }
 catch (  UnsupportedEncodingException e1) {
    System.err.println(commandLine.getValue(encoding) + " is not a valid encoding; using system default encoding for System.out and System.err.");
  }
catch (  SecurityException e2) {
    System.err.println("Security manager is configured to disallow changes to System.out or System.err; using system default encoding.");
  }
  int rule_b=100;
  TranslationRuleDatabase rules=new TranslationRuleDatabase(Parser.DB_NAME,commandLine.getValue(grammar_directory),commandLine.getValue(encoding),true,new BilingualTranslationRuleBinding(),rule_b);
  String word="erforderlich";
  System.out.println("getAll yields " + rules.getAll(word).size() + " rules");
  System.out.println("getNBest yields " + rules.getNBest(word).size() + " rules");
  double x=0.0 - Double.NEGATIVE_INFINITY;
  System.out.println(x);
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.mt.tools

Source Code: CalculatePhrasePairProbs.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Calculates the phrase weights for each phrase pair (in one direction only)
 * using relative frequency estimation.
 * @param args
 */
public static void main(String[] args){
  CommandLineParser commandLine=new CommandLineParser();
  Option<String> input_file=commandLine.addStringOption('i',"input-file","INPUT_FILENAME","name of file containing phrase pairs and preliminary lexprob data");
  Option<Boolean> input_file_gz=commandLine.addBooleanOption("input-file-gzipped",false,"is the input file gzipped");
  Option<String> input_file_encoding=commandLine.addStringOption("input-encoding","INPUT_ENCODING","UTF-8","input file encoding");
  Option<String> output_file=commandLine.addStringOption('o',"output","OUTPUT_FILENAME","file where output will be written");
  Option<String> output_file_encoding=commandLine.addStringOption("output-encoding","OUTPUT_ENCODING","UTF-8","output file encoding");
  Option<Boolean> output_file_gz=commandLine.addBooleanOption("output-text-gzipped",false,"should the output file be gzipped");
  Option<String> input_delimiter_pattern=commandLine.addStringOption('d',"delimiter","PATTERN","\\s+:::\\s+","input file field delimiter pattern");
  Option<String> output_delimiter_pattern=commandLine.addStringOption("output-delimiter","STRING","  :::  ","input file field delimiter");
  commandLine.parse(args);
  Writer outputFile=null;
  try {
    Scanner input;
    if (commandLine.getValue(input_file).equals("-"))     input=new Scanner(System.in);
 else     if (commandLine.getValue(input_file).endsWith(".gz") || commandLine.getValue(input_file_gz))     input=new Scanner(new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(commandLine.getValue(input_file))),commandLine.getValue(input_file_encoding))));
 else     input=new Scanner(new File(commandLine.getValue(input_file)),commandLine.getValue(input_file_encoding));
    if (commandLine.getValue(output_file).equals("-"))     outputFile=new OutputStreamWriter(System.out);
    if (commandLine.getValue(output_file).endsWith(".gz") || commandLine.getValue(output_file_gz))     outputFile=new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(commandLine.getValue(output_file))),commandLine.getValue(output_file_encoding));
 else     outputFile=new OutputStreamWriter(new FileOutputStream(commandLine.getValue(output_file)),commandLine.getValue(output_file_encoding));
    String input_delimiter=commandLine.getValue(input_delimiter_pattern);
    String output_delimiter=commandLine.getValue(output_delimiter_pattern);
    calculate(input,input_delimiter,outputFile,output_delimiter);
    if (outputFile != null) {
      outputFile.flush();
      outputFile.close();
    }
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
  }
catch (  UnsupportedEncodingException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.parser

Source Code: RuleDatabase.java (Click to view .java file)

Method Code:
vote
like

public boolean incompleteMatchExists(String key){
  Cursor cursor=null;
  boolean found=false;
  try {
    cursor=myDatabase.openCursor(null,null);
    DatabaseEntry dbKey=new DatabaseEntry((key + " ").getBytes("UTF-8"));
    DatabaseEntry dbValue=new DatabaseEntry();
    OperationStatus retVal=cursor.getSearchKeyRange(dbKey,dbValue,LockMode.DEFAULT);
    if (retVal == OperationStatus.SUCCESS) {
      String keyString=new String(dbKey.getData(),"UTF-8");
      if (keyString.startsWith(key + " "))       found=true;
    }
  }
 catch (  DatabaseException e) {
    System.err.println("Error accessing database." + e);
    e.printStackTrace();
  }
catch (  UnsupportedEncodingException e) {
    e.printStackTrace();
  }
 finally {
    try {
      cursor.close();
    }
 catch (    DatabaseException de) {
    }
  }
  return found;
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.parser

Source Code: PRuleDatabase.java (Click to view .java file)

Method Code:
vote
like

public boolean incompleteMatchExists(String key){
  Cursor cursor=null;
  boolean found=false;
  try {
    cursor=myDatabase.openCursor(null,null);
    DatabaseEntry dbKey=new DatabaseEntry((key + " ").getBytes(encoding));
    DatabaseEntry dbValue=new DatabaseEntry();
    OperationStatus retVal=cursor.getSearchKeyRange(dbKey,dbValue,LockMode.DEFAULT);
    if (retVal == OperationStatus.SUCCESS) {
      String keyString=new String(dbKey.getData(),"UTF-8");
      if (keyString.startsWith(key + " "))       found=true;
    }
  }
 catch (  DatabaseException e) {
    System.err.println("Error accessing database." + e);
    e.printStackTrace();
  }
catch (  UnsupportedEncodingException e) {
    e.printStackTrace();
  }
 finally {
    try {
      cursor.close();
    }
 catch (    DatabaseException de) {
    }
  }
  return found;
}
 

Project Name: nlp-parsers Package: edu.umn.cs.nlp.test

Source Code: ThreadingDB.java (Click to view .java file)

Method Code:
vote
like

public static void main(String[] args){
  ThreadingDB.createDB("sampleDB","/tmp/sampleDBDir","UTF-8",true);
  try {
    System.setOut(new java.io.PrintStream(System.out,true,"UTF-8"));
    System.setErr(new java.io.PrintStream(System.err,true,"UTF-8"));
  }
 catch (  UnsupportedEncodingException e1) {
  }
  final ThreadingDB db=new ThreadingDB("sampleDB","/tmp/sampleDBDir","UTF-8",true);
  ExecutorService threads=Executors.newFixedThreadPool(4);
  try {
    for (int i=1; i < 10; i++) {
      final int j=i;
      threads.execute(new Runnable(){
        public void run(){
          for (int wait=0; wait < (long)Math.random() * 100000; wait++)           ;
          Collection<String> values=db.getUsingCursor("key" + j);
          for (          String value : values)           System.out.println("Thread " + j + " :  "+ value);
        }
      }
);
    }
    threads.shutdown();
    threads.awaitTermination(Integer.MAX_VALUE,TimeUnit.SECONDS);
  }
 catch (  InterruptedException e) {
    e.printStackTrace();
  }
 finally {
    if (db != null) {
      db.close();
    }
  }
}
 

Project Name: rssowl.core Package: org.rssowl.core.internal.persist.service

Source Code: DBHelper.java (Click to view .java file)

Method Code:
vote
like

public static void writeToFile(File file,String text){
  BufferedWriter writer=null;
  try {
    try {
      writer=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),"UTF-8"));
    }
 catch (    UnsupportedEncodingException e) {
      writer=new BufferedWriter(new FileWriter(file));
    }
    writer.write(text);
    writer.flush();
  }
 catch (  IOException e) {
    throw new PersistenceException(e);
  }
 finally {
    closeQuietly(writer);
  }
}
 

Project Name: rssowl.core Package: org.rssowl.core.util

Source Code: URIUtils.java (Click to view .java file)

Method Code:
vote
like

/** 
 * This is a simple wrapper method for the decode() Method of the URLDecoder.
 * UTF-8 is used for encoding.
 * @param str String to decode
 * @return the URL Decoded String
 */
public static String urlDecode(String str){
  try {
    return URLDecoder.decode(str,DEFAULT_ENCODING);
  }
 catch (  UnsupportedEncodingException e1) {
    return str;
  }
}