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; }
private void printMap(ImmutableMap<String, Integer> map, StringBuffer sb) { for (String key : map.keySet()) { sb.append(key).append(": ").append(map.get(key)).append("\n"); } }
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 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
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; }
PluginFactory pluginFactory = pluginFactories.get(pluginId); Plugin plugin = pluginFactory.createPlugin(); mapOfPlugins.put(pluginId, plugin); InstanceBasedPluginFactory pluginFactory = instanceBasedPluginFactories.get(pluginId); InstanceBasedPlugin plugin = pluginFactory.createPlugin(); mapOfPlugins.put(pluginId, plugin);
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; }
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");}
if (nomlexMap.containsKey(lemma)) this.nominalization = nomlexMap.get(lemma); if (null==nominalization.getVerbs()) throw new PredicateArgumentIdentificationException("A nominal has no verbs: \""+lemma+"\".");
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; }
ArgumentType argumentType = nominalization.getMapArgumentToType().get(observedNomlexArgument); ret.add(new NodeAndPathFromPredicateAndArgumentType<I,S>(current,path,argumentType));