public SubstitutionSubtreeSpecification(String source, ExtendedNode subtreeToRemove, ExtendedNode subtreeToAdd, Set<ExtendedNode> subtreesToOmit) { super(); this.source = (source!=null)?StringUtil.capitalizeFirstLetter(source):null; this.subtreeToRemove = subtreeToRemove; this.subtreeToAdd = subtreeToAdd; this.subtreesToOmit = subtreesToOmit; }
public void setCacheCapacity(int cacheCapacity) { cache = new CacheFactory<LemmaAndPos, ImmutableSet<T>>().getCache(cacheCapacity); }
/** * execute the sentence-splitting command * * @param command * @param reader * @return * @throws ProgramExecutionException * @throws InterruptedException */ private LinkedList<String> executeCommandWithReader( LinkedList<String> command, Reader reader) throws ProgramExecutionException, InterruptedException { ProgramExecution execution = new ProgramExecution(command, reader); execution.execute(); LinkedList<String> out = execution.getOutput(); // if the return value is't 0, there's probably a runtime error int ex = 1; ex = execution.getExitValue(); if (0 != ex) throw new ProgramExecutionException("tokenizer returned an irregular exit value " + ex + ". Make sure cygwin is installed."); return out; }
public void createTemplate() throws TeEngineMlException { templates = null; Set<String> theTemplates = null; if (cache.containsKey(tree)) { synchronized(cache) { if (cache.containsKey(tree)) // the if condition appears twice, for efficiency (avoiding synchronized if possible). { theTemplates = cache.get(tree); } } } if (null==theTemplates) { theTemplates = createTemplateNotInCache(); cache.put(tree, theTemplates); } templates = sortAndSeal(theTemplates); }
public void main(Class<?> cls, String[] args) { Logger logger = null; try { logger = mainCanThrowExceptions(cls, args); } catch (Throwable e) { ExceptionUtil.outputException(e, System.out); if (logger!=null) { ExceptionUtil.logException(e, logger); } } }
private static Set<String> getOptions(String variedParam) { return variedParam != null ? Utils.arrayToCollection(variedParam.split(OR_REGEX), new LinkedHashSet<String>()) : null; } }
public void addToLogAndExperimentManager(Logger logger) { if (messagesLogged()) { String messages = getMessages(); logger.log(DEFAULT_LEVEL, messages); ExperimentManager.getInstance().addMessage(messages); } }
protected void saveSamples(Vector<LabeledSample> samples, int useCounter, String searchPredictionsIndicator) throws FileNotFoundException, IOException { File file = new File(BiuteeConstants.LABELED_SAMPLES_FILE_PREFIX+useCounter+BiuteeConstants.LABELED_SAMPLES_FILE_POSTFIX); try(ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(file))) { stream.writeObject(samples); } ExperimentManager.getInstance().register(file); }
private String totallyOmittedString(String prefix, Set<String> words) { if (null==words) return ""; if (words.size()==0) return ""; return prefix+StringUtil.joinIterableToString(words, ", ",true)+"\n"; }
public void run() { logger.error("Exception!",ex); try { String exceptionMessages = ExceptionUtil.getMessages(ex); JOptionPane.showMessageDialog(parentComponent, "Exception! See log (usually also printed to console)\n"+exceptionMessages,"An error occurred",JOptionPane.ERROR_MESSAGE); } catch(Exception xx){} } };
/** * Returns the "java" program, which is currently running. * It should be $JAVA_HOME/bin/java (or %JAVA_HOME%\bin\java.exe), where * the JAVA_HOME is the home of the JDK or JRE. * @return */ private static File getJavaExecutable() { String javaHome = System.getProperty("java.home"); File javaHomeDir = new File(javaHome); return new File(new File(javaHomeDir,"bin"),OS.programName("java")); }
private boolean samePredicate(Predicate<I, S> hypothesisPredicate, Predicate<I, S> textPredicate) { return (Utils.intersect( predicateLemmasLowerCase(hypothesisPredicate), predicateLemmasLowerCase(textPredicate), new LinkedHashSet<String>() ).size()>0); }
private static boolean isContentVerb(Info info) { boolean ret = false; if (isVerb(info)) { String lemma = InfoGetFields.getLemma(info); if (!StringUtil.setContainsIgnoreCase(NON_CONTENT_VERBS, lemma)) ret = true; } return ret; }
/** * After you are done with this converter, call this method * to clean up. * Don't call any other method of this converter later. */ public void end() { if (!finalizationDone) { if (execution!=null) { try{execution.endIO();}catch(Exception e){} try{convertionFile.delete();}catch(Exception e){} execution = null; convertionFile = null; finalizationDone = true; } } }
@Override public String toShortString() { StringBuffer ret = new StringBuffer(); ret.append(StringUtil.capitalizeFirstLetterOnly(ruleBaseName)); if (extraction) ret.append(" extraction"); else ret.append(" substitution"); return ret.toString(); }
public static boolean infoIsNumber(Info info) { String lemma = InfoGetFields.getLemma(info); return StringUtil.isNumber(lemma); }
public static boolean infoHasLemma(Info info) { boolean ret = false; String lemma = InfoGetFields.getLemma(info, ""); lemma = lemma.trim(); if ( ( StringUtil.hasNeitherLetterNorDigit(lemma) ) || (MINIPAR_NON_WORDS_LEMMAS.contains(lemma)) ) ret = false; else ret = true; return ret; }
protected void setDocumentImpl(InputStream documentStream) throws SentenceSplitterException { try { setDocument(StringUtil.convertStreamToString(documentStream)); } catch (IOException e) { throw new SentenceSplitterException("error with InputStream, see nested.",e); } }
public void windowClosing(WindowEvent e) { System.out.println("window closing"); try{execution.endIO();}catch(Exception x){} try{converter.end();}catch(Exception x){} System.exit(0); } }