cacheForHypothesisTemplates.put(hypothesisTemplate, results);
public T getClassifier(Vector<LabeledSample> samples) throws ClassifierException { T ret = null; synchronized(this) { if (pool.containsKey(samples)) { logger.info("Classifier exists in pool"); ret = pool.get(samples); } } if (null==ret) { logger.info("Creating a new classifier, since it does not exist in pool"); ret = createClassifier(); ret.train(samples); synchronized(this) { pool.put(samples,ret); } } return ret; }
cacheRules.put(leftHandSide, ret);
synchronized(cacheHypothesisToTemplates) cacheHypothesisToTemplates.put(sealedOriginalHypothesisTree, ret);
/** * Returns the rules (i.e., chains) whose right-hand-side is the given word. * * @param hypothesisLemma * @return * @throws LexicalResourceException * @throws TeEngineMlException */ private ValueSetMap<CanonicalLemmaAndPos, ChainOfLexicalRules> getForSingleHypothesisWord(CanonicalLemmaAndPos hypothesisLemma) throws LexicalResourceException, TeEngineMlException { boolean retrieved = false; ValueSetMap<CanonicalLemmaAndPos, ChainOfLexicalRules> rulesSingleWord = null; if (cacheGeneratedForSingleWord.containsKey(hypothesisLemma)) { rulesSingleWord = cacheGeneratedForSingleWord.get(hypothesisLemma); retrieved = true; } if (!retrieved) { logger.debug("retrieving rules using BuilderSingleWord"); BuilderSingleWord builderSingleWord = new BuilderSingleWord(hypothesisLemma, resources); builderSingleWord.createRuleBase(depth); rulesSingleWord = builderSingleWord.getGeneratedRules(); cacheGeneratedForSingleWord.put(hypothesisLemma, rulesSingleWord); } return rulesSingleWord; }
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); }
rhsResults.add(new TemplateAndScore(description, score)); cache.put(template, rhsResults); if (logger.isDebugEnabled()){logger.debug(""+rhsResults.size()+" templates loaded from data-base for template"+template);}
@Override public ImmutableSet<T> getRules(String lhsLemma, PartOfSpeech lhsPos) throws RuleBaseException { try { ImmutableSet<T> ret = null; LemmaAndPos lemmaAndPos = new LemmaAndPos(lhsLemma, lhsPos); if (cache.containsKey(lemmaAndPos)) { ret = cache.get(lemmaAndPos); } else { ret = getRulesNotInCache(lhsLemma,lhsPos); cache.put(lemmaAndPos, ret); } return ret; } catch(TeEngineMlException e) { throw new RuleBaseException("An error occured for the given lemma and part-of-speech. See nested exception",e); } }
synchronized(cache) cache.put(tree, ret);
private ImmutableList<String> getLemmas(String word) throws LemmatizerException { ImmutableList<String> ret = null; boolean retrievedFromCache=false; if (lemmatizerCache.containsKey(word)) { synchronized(lemmatizerCache) { if (lemmatizerCache.containsKey(word)) { ret = lemmatizerCache.get(word); retrievedFromCache=true; } } } if (!retrievedFromCache) { synchronized(lemmatizer) { lemmatizer.set(word); lemmatizer.process(); ret = lemmatizer.getLemmas(); } lemmatizerCache.put(word,ret); } return ret; }
private ParseTreeCharacteristics<Info, BasicNode> getCharacteristicsOfRule(RuleWithConfidenceAndDescription<Info, BasicNode> rule) { ParseTreeCharacteristics<Info, BasicNode> ret = null; BasicNode lhs = rule.getRule().getLeftHandSide(); if (ruleBaseCharacteristicsCache.containsKey(lhs)) { ret = ruleBaseCharacteristicsCache.get(lhs); } else { ParseTreeCharacteristicsCollector<Info, BasicNode> collector = new ParseTreeCharacteristicsCollector<Info, BasicNode>(lhs); collector.extract(); ret = new ParseTreeCharacteristics<Info, BasicNode>(collector.getPosRelPosSet(),collector.getLemmaAndPosSet()); ruleBaseCharacteristicsCache.put(lhs, ret); } return ret; }