List of usage examples for java.util HashMap containsKey
public boolean containsKey(Object key)
From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java
/** * Finds the probability of word1 transliterating to word2 over all possible alignments * This is Algorithm 1 in the paper./*from w w w.ja va 2 s . c o m*/ * @param word1 Source word * @param word2 Transliterated word * @param maxSubstringLength1 constant field from SPModel * @param maxSubstringLength2 constant field from SPModel * @param probs map from production to weight?? * @param memoizationTable * @param minProductionProbability * @return */ public static double GetSummedAlignmentProbability(String word1, String word2, int maxSubstringLength1, int maxSubstringLength2, HashMap<Production, Double> probs, HashMap<Production, Double> memoizationTable, double minProductionProbability, int origin) { if (memoizationTable.containsKey(new Production(word1, word2, origin))) { return memoizationTable.get(new Production(word1, word2, origin)); } if (word1.length() == 0 && word2.length() == 0) //record probabilities return 1; //null -> null is always a perfect alignment double probSum = 0; int maxSubstringLength1f = Math.min(word1.length(), maxSubstringLength1); int maxSubstringLength2f = Math.min(word2.length(), maxSubstringLength2); double localMinProdProb = 1; for (int i = 1; i <= maxSubstringLength1f; i++) //for each possible substring in the first word... { localMinProdProb *= minProductionProbability; String substring1 = word1.substring(0, i); for (int j = 1; j <= maxSubstringLength2f; j++) //for possible substring in the second { //if we get rid of these characters, can we still cover the remainder of word2? if ((word1.length() - i) * maxSubstringLength2 >= word2.length() - j && (word2.length() - j) * maxSubstringLength1 >= word1.length() - i) { String substring2 = word2.substring(0, j); Production production = new Production(substring1, substring2, origin); double prob = 0; if (!probs.containsKey(production)) { if (localMinProdProb == 0) { continue; } } else { prob = probs.get(production); } prob = Math.max(prob, localMinProdProb); double remainderProbSum = GetSummedAlignmentProbability(word1.substring(i), word2.substring(j), maxSubstringLength1, maxSubstringLength2, probs, memoizationTable, minProductionProbability, origin); //update our probSum probSum += remainderProbSum * prob; } } } memoizationTable.put(new Production(word1, word2), probSum); return probSum; }
From source file:nz.org.geonet.mule.MuleMetricsTestCase.java
/** * The Mule component (Metrics) does not return a message to the flow so we cannot test it directly. * Start Mule up and get a Spring bean from the registry to check the wiring and metrics code. * * @throws Exception//w ww. j a v a 2 s.c o m */ @Test public void muleMetrics() throws Exception { MuleClient client = muleContext.getClient(); ApplicationContext applicationContext = muleContext.getRegistry() .lookupObject(SpringRegistry.SPRING_APPLICATION_CONTEXT); MuleCollector collector = (MuleCollector) applicationContext.getBean("collector"); HashMap<String, Number> results = collector.gather(); assertTrue("Map has Threading.used", results.containsKey("Threading.used")); assertTrue("Map has Threading.max", results.containsKey("Threading.max")); assertTrue("Map has HeapMemoryUsage.used", results.containsKey("HeapMemoryUsage.used")); assertTrue("Map has HeapMemoryUsage.max", results.containsKey("HeapMemoryUsage.max")); assertTrue("Map has Classes.totalLoaded", results.containsKey("Classes.totalLoaded")); }
From source file:com.deploymentio.ec2namer.helpers.InstanceTagger.java
/** * Tags the EC2 instance we are naming. The tag's name/values are provided * in the request. Additionally, if no <code>Name</code> tag is provided, * this method will add one in the format of * <code>{environment}:{reserved-name}</code>. * //from w ww. j a v a2 s.c om * @param req * the namer request * @param context * the lambda function execution context * @param name * the reserved name for this instance * @throws IOException * if the instance cannot be tagged */ public void tag(NamerRequest req, LambdaContext context, ReservedName name) throws IOException { HashMap<String, String> map = new HashMap<>(req.getRequestedTags()); if (!map.containsKey("Name")) { map.put("Name", req.getEnvironment() + ":" + name.getHostname()); } ArrayList<Tag> tags = new ArrayList<>(); for (String key : map.keySet()) { String val = map.get(key); tags.add(new Tag().withKey(key).withValue(val)); } ec2.createTags(new CreateTagsRequest().withResources(req.getInstanceId()).withTags(tags)); }
From source file:org.ontosoft.server.repository.plugins.GithubPlugin.java
private void addDocumentationMetadata(String userid, String repoid, PluginResponse response) { String ontns = KBConstants.ONTNS(); String resource = "/repos/" + userid + "/" + repoid + "/readme"; HashMap<String, Object> vals = getResource(resource); if (vals.containsKey("download_url")) { String docurl = (String) vals.get("download_url"); if (docurl != null && !docurl.equals("")) response.addSuggestedMetadata(ontns + "hasDocumentation", docurl); }/*from w w w . j av a 2s . c om*/ }
From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java
public static HashMap<String, Double> GetSourceSubstringMax(HashMap<Pair<String, String>, Double> counts) { HashMap<String, Double> result = new HashMap<>(counts.size()); for (Pair<String, String> key : counts.keySet()) { Double value = counts.get(key); if (result.containsKey(key.getFirst())) result.put(key.getFirst(), Math.max(value, result.get(key.getFirst()))); else//from w w w . j a v a 2 s .com result.put(key.getFirst(), value); } return result; }
From source file:org.ontosoft.server.repository.plugins.GithubPlugin.java
@SuppressWarnings("unchecked") private void addRepositoryMetadata(String userid, String repoid, PluginResponse response) { String ontns = KBConstants.ONTNS(); String resource = "/repos/" + userid + "/" + repoid; HashMap<String, Object> vals = getResource(resource); if (vals.containsKey("license")) { HashMap<String, String> licobj = (HashMap<String, String>) vals.get("license"); if (licobj != null && licobj.containsKey("name")) response.addSuggestedMetadata(ontns + "hasLicense", licobj.get("name")); }/*from www .j av a 2s . c o m*/ if (vals.containsKey("homepage") && vals.get("homepage") != null) response.addSuggestedMetadata(ontns + "hasProjectWebsite", vals.get("homepage")); if (vals.containsKey("description") && !("".equals(vals.get("description")))) response.addSuggestedMetadata(ontns + "hasShortDescription", vals.get("description")); }
From source file:hu.ppke.itk.nlpg.purepos.model.internal.HashSuffixTree.java
protected void increment(String suffix, T tag, int count) { if (representation.containsKey(suffix)) { MutablePair<HashMap<T, Integer>, Integer> value = representation.get(suffix); HashMap<T, Integer> tagCounts = value.getLeft(); if (tagCounts.containsKey(tag)) { tagCounts.put(tag, tagCounts.get(tag) + count); } else {/*from w w w . ja v a 2s. co m*/ tagCounts.put(tag, count); } value.setRight(value.getRight() + count); } else { HashMap<T, Integer> tagCounts = new HashMap<T, Integer>(); tagCounts.put(tag, count); MutablePair<HashMap<T, Integer>, Integer> value = new MutablePair<HashMap<T, Integer>, Integer>( tagCounts, count); representation.put(suffix, value); } }
From source file:org.archone.ad.security.AdAccessPolicy.java
@SecurityConstraint(name = "administrator.by_domain") public void validateEntityAccess(OperationContext opContext) throws InvalidNameException, NamingException { HashMap<String, Object> params = opContext.getParams(); String domain = null;/* w w w. java 2s .c om*/ if (params.containsKey("domain")) { DomainDn domainDn = nameHelper.newDomainDnFromDomain((String) params.get("domain")); domain = domainDn.getDomain(); } if (params.containsKey("groupId")) { GroupDn groupDn = nameHelper.newGroupDnFromId((String) params.get("groupId")); domain = groupDn.getDomain(); } if (params.containsKey("userId")) { UserDn userDn = nameHelper.newUserDnFromId((String) params.get("userId")); domain = userDn.getDomain(); } if (domain != null && !userHelper.getAdminDomains().contains(domain)) { throw new SecurityViolationException(); } if (params.containsKey("groups")) { List<String> groups = (List<String>) params.get("groups"); for (String group : groups) { GroupDn groupDn = nameHelper.newGroupDnFromId(group); if (!userHelper.isAdminDomain(domain)) { throw new SecurityViolationException(domain + " is forbidden"); } } } }
From source file:hmp.Read.java
private void addToHash(HashMap<String, SummaryStatistics> hash, String key, double value) { if (hash.containsKey(key)) { SummaryStatistics stat = hash.get(key); stat.addValue(value);/*from w w w . j a va 2 s .c o m*/ } else { SummaryStatistics stat = new SummaryStatistics(); stat.addValue(value); hash.put(key, stat); } }
From source file:it.jugpadova.blo.ParticipantBadgeBo.java
protected int getParticipantsPerPage(Event event) throws IOException { int count = 0; InputStream templateIs = getBadgePageTemplateInputStream(event); RandomAccessFileOrArray rafa = new RandomAccessFileOrArray(templateIs); PdfReader template = new PdfReader(rafa, null); AcroFields form = template.getAcroFields(); HashMap fields = form.getFields(); while (true) { if (fields.containsKey("firstName" + (count + 1))) { count++;/* w w w . j ava 2s. c om*/ } else { break; } } template.close(); return count; }