public Plugin getPlugin(String pluginId) throws TeEngineMlException { if (!this.mapPlugins.containsKey(pluginId)) throw new TeEngineMlException("Plugin \""+pluginId+"\" does not exist."); return this.mapPlugins.get(pluginId); } public ImmutableSet<InstanceBasedPlugin> getInstanceBasedPlugins() throws TeEngineMlException
@Override public AdaptedFeatureVectorStructure marshal(FeatureVectorStructure v) throws Exception { return new AdaptedFeatureVectorStructure(v.getRuleBasesFeatures().getMutableCopy(),v.getPluginFeatures().getMutableCopy(),v.getDynamicGlobalFeatures().getMutableCopy(),v.getPredefinedFeaturesNames()); }
/** * Finds the nominal predicates in the parse tree. */ public void identify() { predicateHeads = new LinkedHashSet<S>(); for (S node : TreeIterator.iterableTree(tree.getTree())) { if (SimplerCanonicalPosTag.NOUN.equals(SimplerPosTagConvertor.simplerPos(InfoGetFields.getCanonicalPartOfSpeech(node.getInfo())))) { if (nomlexMap.keySet().contains(InfoGetFields.getLemma(node.getInfo()).trim().toLowerCase(Locale.ENGLISH))) { predicateHeads.add(node); } } } }
public Map<Integer,Double> byName(Map<Integer,Double> originalFeatureVector, String customFeatureName, double valueToAdd) throws TeEngineMlException { Map<Integer,Double> featureVector = new LinkedHashMap<Integer, Double>(); featureVector.putAll(originalFeatureVector); Integer customfeatureIndex = imMapCustomFeatureToFeatureIndex.get(customFeatureName); updateFeatureVector(featureVector, customfeatureIndex, valueToAdd); return featureVector; }
public ImmutableSet<String> getAllowedDatasetNames() throws TeEngineMlException { if (null==this.teSystemEnvironment.getFeatureVectorStructureOrganizer().getDynamicGlobalFeatures()) { return new ImmutableSetWrapper<String>(new DummySet<String>()); } else { return this.teSystemEnvironment.getFeatureVectorStructureOrganizer().getDynamicGlobalFeatures().keySet(); } }
private void createMapTypeToArgument() { Map<ArgumentType, Set<NomlexArgument>> map = new LinkedHashMap<ArgumentType, Set<NomlexArgument>>(); for (NomlexArgument argument : mapArgumentToType.keySet()) { ArgumentType type = mapArgumentToType.get(argument); if (null==map.get(type)) { map.put(type, new LinkedHashSet<NomlexArgument>()); } map.get(type).add(argument); } mapTypeToArgument = new ImmutableMapWrapper<ArgumentType, Set<NomlexArgument>>(map); }
public Map<Integer,Double> forRuleWithConfidence(Map<Integer,Double> originalFeatureVector, String ruleBaseName, double confidence) throws TeEngineMlException { Map<Integer,Double> featureVector = new LinkedHashMap<Integer, Double>(); featureVector.putAll(originalFeatureVector); if (!imMapRuleBaseNameToFeatureIndex.containsKey(ruleBaseName)) throw new TeEngineMlException("Rule base: "+ruleBaseName+" is unrecognized."); Integer featureIndex = imMapRuleBaseNameToFeatureIndex.get(ruleBaseName); if (null==featureIndex) throw new TeEngineMlException("Rule base: "+ruleBaseName+" has null index, which is an anomaly."); Double origValue = originalFeatureVector.get(featureIndex); if (null==origValue) origValue=0.0; double valueToAdd = Math.log(confidence); if (valueToAdd>=0)throw new TeEngineMlException("Non-negative value to feature value for feature: "+featureIndex+". Value is: "+String.format("%3.3f", valueToAdd) ); Double newValue = origValue+valueToAdd; if (newValue>=0) throw new TeEngineMlException("Non-negative value to feature value for feature: "+featureIndex+". Value is: "+String.format("%3.3f", newValue) ); featureVector.put(featureIndex,newValue); return featureVector; }
if (map1.keySet().equals(map2.keySet())) for (K k : map1.keySet()) if (!map1.get(k).equals(map2.get(k))) ret = new BooleanAndString(false, "Value of "+k+" in "+map1Name+" is "+map1.get(k)+" and is differ from the value in "+map2Name+" which is "+map2.get(k)); break; ImmutableSet<K> map2KeySet = map2.keySet(); for (K k : map1.keySet()) ImmutableSet<K> map1KeySet = map1.keySet(); for (K k : map2.keySet())
public Map<Integer, Double> forChainOfRules(Map<Integer, Double> originalFeatureVector, ImmutableList<ConfidenceChainItem> chain) throws TeEngineMlException { Map<Integer, Double> featureVector = new LinkedHashMap<Integer, Double>(); featureVector.putAll(originalFeatureVector); for (ConfidenceChainItem item : chain) { if (!imMapRuleBaseNameToFeatureIndex.containsKey(item.getRuleBaseName()))throw new TeEngineMlException("rule base: "+item.getRuleBaseName()+" does not exist."); Integer featureIndex = imMapRuleBaseNameToFeatureIndex.get(item.getRuleBaseName()); if (null==featureIndex)throw new TeEngineMlException("rule base: "+item.getRuleBaseName()+" does not exist."); Double origValue = featureVector.get(featureIndex); if (null==origValue)origValue=0.0; double valueToAdd = Math.log(item.getConfidence()); if (valueToAdd>=0)throw new TeEngineMlException("Non-negative value to feature value for feature: "+featureIndex+" of rule-base: "+item.getRuleBaseName()+". Value is: "+String.format("%3.3f", valueToAdd) ); Double newValue = origValue+valueToAdd; if (newValue>=0) throw new TeEngineMlException("Non-negative value to feature value for feature: "+featureIndex+". Value is: "+String.format("%3.3f", newValue) ); featureVector.put(featureIndex, newValue); } return featureVector; }
ImmutableMap<String, InstanceBasedPluginFactory> instanceBasedPluginFactories = pluginRegistry.getImmutableRegisteredInstanceBasedPlugins(); for (String pluginId : pluginFactories.keySet()) PluginFactory pluginFactory = pluginFactories.get(pluginId); Plugin plugin = pluginFactory.createPlugin(); mapOfPlugins.put(pluginId, plugin); for (String pluginId : instanceBasedPluginFactories.keySet()) InstanceBasedPluginFactory pluginFactory = instanceBasedPluginFactories.get(pluginId); InstanceBasedPlugin plugin = pluginFactory.createPlugin(); mapOfPlugins.put(pluginId, plugin);
public void identify() throws PredicateArgumentIdentificationException if (nomlexMap.containsKey(lemma)) this.nominalization = nomlexMap.get(lemma); if (null==nominalization.getVerbs()) throw new PredicateArgumentIdentificationException("A nominal has no verbs: \""+lemma+"\".");
public Set<Integer> getAllIndexesOfFeatures() throws TeEngineMlException { if (!built) throw new TeEngineMlException("FeatureVectorStructureOrganizer.getNumberOfFeatures() failed. Reason: Not yet built!"); Set<Integer> ret = new LinkedHashSet<Integer>(); for (Feature feature : Feature.values()) { ret.add(feature.getFeatureIndex()); } @SuppressWarnings("unchecked") ImmutableMap<String,Integer>[] maps = (ImmutableMap<String,Integer>[]) new ImmutableMap[]{ getRuleBasesFeatures(),getPluginFeatures(),getDynamicGlobalFeatures()}; for (ImmutableMap<String,Integer> map : maps) { for (String key : map.keySet()) { ret.add(map.get(key)); } } return ret; }
ImmutableMap<String,Integer> dynamicGlobalFeatures = featureVectorStructure.getDynamicGlobalFeatures(); boolean containsOK = false; if (dynamicGlobalFeatures.containsKey(datasetName)) { if (dynamicGlobalFeatures.get(datasetName)!=null) Integer featureIndexForDatasetName = dynamicGlobalFeatures.get(datasetName); ret.put(featureIndexForDatasetName, 1.0); if (logger.isDebugEnabled()){logger.debug("Setting feature "+featureIndexForDatasetName+" for dataset-name \""+datasetName+"\" value of 1.0");}
public Map<Integer, String> createMapOfFeatureNames() throws TeEngineMlException { if (!built) throw new TeEngineMlException("Not yet built!"); Map<Integer, String> ret = new LinkedHashMap<Integer, String>(); for (Feature feature : Feature.values()) { addKeyValueToMap(ret,feature.getFeatureIndex(),feature.name()); } @SuppressWarnings("unchecked") ImmutableMap<String,Integer>[] maps = (ImmutableMap<String,Integer>[]) new ImmutableMap[]{ruleBasesFeatures,pluginFeatures,dynamicGlobalFeatures}; for (ImmutableMap<String,Integer> map : maps) { for (String str : map.keySet()) { addKeyValueToMap(ret,map.get(str),str); } } return ret; }
if (nominalization.getMapArgumentToType().containsKey(observedNomlexArgument)) ArgumentType argumentType = nominalization.getMapArgumentToType().get(observedNomlexArgument); ret.add(new NodeAndPathFromPredicateAndArgumentType<I,S>(current,path,argumentType));