List of usage examples for org.apache.commons.lang ArrayUtils addAll
public static double[] addAll(double[] array1, double[] array2)
Adds all the elements of the given arrays into a new array.
From source file:de.tudarmstadt.ukp.dkpro.core.corenlp.CoreNlpParserTest.java
private JCas runTest(String aLanguage, String aVariant, String aText, Object... aExtraParams) throws Exception { AssumeResource.assumeResource(CoreNlpParser.class, "de/tudarmstadt/ukp/dkpro/core/stanfordnlp", "parser", aLanguage, aVariant);//from w ww. j a v a 2s. c om AggregateBuilder aggregate = new AggregateBuilder(); Object[] params = new Object[] { CoreNlpParser.PARAM_VARIANT, aVariant, CoreNlpParser.PARAM_PRINT_TAGSET, true, CoreNlpParser.PARAM_WRITE_CONSTITUENT, true, CoreNlpParser.PARAM_WRITE_DEPENDENCY, true, CoreNlpParser.PARAM_WRITE_PENN_TREE, true, CoreNlpParser.PARAM_READ_POS, false, CoreNlpParser.PARAM_WRITE_POS, true }; params = ArrayUtils.addAll(params, aExtraParams); aggregate.add(createEngineDescription(CoreNlpParser.class, params)); return TestRunner.runTest(aggregate.createAggregateDescription(), aLanguage, aText); }
From source file:de.tudarmstadt.ukp.dkpro.core.stanfordnlp.StanfordParserTest.java
private JCas runTestWithPosTagger(String aLanguage, String aVariant, String aText, Object... aExtraParams) throws Exception { AssumeResource.assumeResource(StanfordPosTagger.class, "tagger", aLanguage, null); AssumeResource.assumeResource(StanfordParser.class, "parser", aLanguage, aVariant); AggregateBuilder aggregate = new AggregateBuilder(); aggregate.add(createEngineDescription(StanfordPosTagger.class)); Object[] params = new Object[] { StanfordParser.PARAM_VARIANT, aVariant, StanfordParser.PARAM_PRINT_TAGSET, true, StanfordParser.PARAM_WRITE_CONSTITUENT, true, StanfordParser.PARAM_WRITE_DEPENDENCY, true, StanfordParser.PARAM_WRITE_PENN_TREE, true, StanfordParser.PARAM_READ_POS, true, StanfordParser.PARAM_WRITE_POS, false }; params = ArrayUtils.addAll(params, aExtraParams); aggregate.add(createEngineDescription(StanfordParser.class, params)); return TestRunner.runTest(aggregate.createAggregateDescription(), aLanguage, aText); }
From source file:de.tudarmstadt.ukp.dkpro.core.stanfordnlp.StanfordParserTest.java
private JCas runTest(String aLanguage, String aVariant, String aText, Object... aExtraParams) throws Exception { AssumeResource.assumeResource(StanfordParser.class, "parser", aLanguage, aVariant); AggregateBuilder aggregate = new AggregateBuilder(); Object[] params = new Object[] { StanfordParser.PARAM_VARIANT, aVariant, StanfordParser.PARAM_PRINT_TAGSET, true, StanfordParser.PARAM_WRITE_CONSTITUENT, true, StanfordParser.PARAM_WRITE_DEPENDENCY, true, StanfordParser.PARAM_WRITE_PENN_TREE, true, StanfordParser.PARAM_WRITE_POS, true }; params = ArrayUtils.addAll(params, aExtraParams); aggregate.add(createEngineDescription(StanfordParser.class, params)); return TestRunner.runTest(aggregate.createAggregateDescription(), aLanguage, aText); }
From source file:au.org.ala.biocache.dao.SearchDAOImpl.java
/** * Calculates the breakdown of the supplied query based on the supplied params *///from w w w.ja va 2 s . com public TaxaRankCountDTO calculateBreakdown(BreakdownRequestParams queryParams) throws Exception { logger.debug("Attempting to find the counts for " + queryParams); TaxaRankCountDTO trDTO = null; SolrQuery solrQuery = new SolrQuery(); solrQuery.setQueryType("standard"); formatSearchQuery(queryParams); solrQuery.setQuery(buildSpatialQueryString(queryParams)); queryParams.setPageSize(0); solrQuery.setFacet(true); solrQuery.setFacetMinCount(1); solrQuery.setFacetSort("count"); solrQuery.setFacetLimit(-1); //add the context information updateQueryContext(queryParams); //add the rank:name as a fq if necessary if (StringUtils.isNotEmpty(queryParams.getName()) && StringUtils.isNotEmpty(queryParams.getRank())) { queryParams.setFq((String[]) ArrayUtils.addAll(queryParams.getFq(), new String[] { queryParams.getRank() + ":" + queryParams.getName() })); } //add the ranks as facets if (queryParams.getLevel() == null) { List<String> ranks = queryParams.getRank() != null ? searchUtils.getNextRanks(queryParams.getRank(), queryParams.getName() == null) : searchUtils.getRanks(); for (String r : ranks) { solrQuery.addFacetField(r); } } else { //the user has supplied the "exact" level at which to perform the breakdown solrQuery.addFacetField(queryParams.getLevel()); } QueryResponse qr = runSolrQuery(solrQuery, queryParams); if (queryParams.getMax() != null && queryParams.getMax() > 0) { //need to get the return level that the number of facets are <=max ranks need to be processed in reverse order until max is satisfied if (qr.getResults().getNumFound() > 0) { List<FacetField> ffs = qr.getFacetFields(); //reverse the facets so that they are returned in rank reverse order species, genus, family etc Collections.reverse(ffs); for (FacetField ff : ffs) { //logger.debug("Handling " + ff.getName()); trDTO = new TaxaRankCountDTO(ff.getName()); if (ff.getValues() != null && ff.getValues().size() <= queryParams.getMax()) { List<FieldResultDTO> fDTOs = new ArrayList<FieldResultDTO>(); for (Count count : ff.getValues()) { FieldResultDTO f = new FieldResultDTO(count.getName(), count.getCount()); fDTOs.add(f); } trDTO.setTaxa(fDTOs); break; } } } } else if (queryParams.getRank() != null || queryParams.getLevel() != null) { //just want to process normally the rank to facet on will start with the highest rank and then go down until one exists for if (qr.getResults().getNumFound() > 0) { List<FacetField> ffs = qr.getFacetFields(); for (FacetField ff : ffs) { trDTO = new TaxaRankCountDTO(ff.getName()); if (ff != null && ff.getValues() != null) { List<Count> counts = ff.getValues(); if (counts.size() > 0) { List<FieldResultDTO> fDTOs = new ArrayList<FieldResultDTO>(); for (Count count : counts) { FieldResultDTO f = new FieldResultDTO(count.getName(), count.getCount()); fDTOs.add(f); } trDTO.setTaxa(fDTOs); break; } } } } } return trDTO; }
From source file:au.org.ala.biocache.dao.SearchDAOImpl.java
/** * Format the search input query for a full-text search. * * This includes constructing a user friendly version of the query to * be used for display purposes./*from w w w .java 2s.c o m*/ * * TODO Fix this to use a state. REVISE!! * * @param searchParams */ protected void formatSearchQuery(SpatialSearchRequestParams searchParams, boolean forceQueryFormat) { //Only format the query if it doesn't already supply a formattedQuery. if (forceQueryFormat || StringUtils.isEmpty(searchParams.getFormattedQuery())) { // set the query String query = searchParams.getQ(); //cached query parameters are already formatted if (query.contains("qid:")) { Matcher matcher = qidPattern.matcher(query); long qid = 0; while (matcher.find()) { String value = matcher.group(); try { String qidValue = SearchUtils.stripEscapedQuotes(value.substring(4)); qid = Long.parseLong(qidValue); ParamsCacheObject pco = ParamsCache.get(qid); if (pco != null) { searchParams.setQId(qid); searchParams.setQ(pco.getQ()); //add the fqs from the params cache if (pco.getFqs() != null) { String[] currentFqs = searchParams.getFq(); if (currentFqs == null || (currentFqs.length == 1 && currentFqs[0].length() == 0)) { searchParams.setFq(pco.getFqs()); } else { //we need to add the current Fqs together searchParams.setFq((String[]) ArrayUtils.addAll(currentFqs, pco.getFqs())); } } String displayString = pco.getDisplayString(); if (StringUtils.isNotEmpty(pco.getWkt())) { displayString = displayString + " within user defined polygon"; } searchParams.setDisplayString(displayString); if (searchParams instanceof SpatialSearchRequestParams) { ((SpatialSearchRequestParams) searchParams).setWkt(pco.getWkt()); } else if (StringUtils.isNotEmpty(pco.getWkt())) { String originalQ = searchParams.getQ(); searchParams.setQ(spatialField + ":\"Intersects(" + pco.getWkt() + ")"); if (StringUtils.isNotEmpty(originalQ)) searchParams.setQ(searchParams.getQ() + " AND " + originalQ); } searchParams.setFormattedQuery(searchParams.getQ()); return; } } catch (NumberFormatException e) { } catch (ParamsCacheMissingException e) { } } } StringBuffer queryString = new StringBuffer(); StringBuffer displaySb = new StringBuffer(); String displayString = query; // look for field:term sub queries and catch fields: matched_name & matched_name_children if (query.contains(":")) { // will match foo:bar, foo:"bar bash" & foo:bar\ bash Matcher matcher = termPattern.matcher(query); queryString.setLength(0); while (matcher.find()) { String value = matcher.group(); logger.debug("term query: " + value); logger.debug("groups: " + matcher.group(1) + "|" + matcher.group(2)); if ("matched_name".equals(matcher.group(1))) { // name -> accepted taxon name (taxon_name:) String field = matcher.group(1); String queryText = matcher.group(2); if (queryText != null && !queryText.isEmpty()) { String guid = speciesLookupService.getGuidForName(queryText.replaceAll("\"", "")); // strip any quotes logger.info("GUID for " + queryText + " = " + guid); if (guid != null && !guid.isEmpty()) { String acceptedName = speciesLookupService.getAcceptedNameForGuid(guid); // strip any quotes logger.info("acceptedName for " + queryText + " = " + acceptedName); if (acceptedName != null && !acceptedName.isEmpty()) { field = "taxon_name"; queryText = acceptedName; } } else { field = "taxon_name"; } // also change the display query displayString = displayString.replaceAll("matched_name", "taxon_name"); } if (StringUtils.containsAny(queryText, CHARS) && !queryText.startsWith("[")) { // quote any text that has spaces or colons but not range queries queryText = QUOTE + queryText + QUOTE; } logger.debug("queryText: " + queryText); matcher.appendReplacement(queryString, matcher.quoteReplacement(field + ":" + queryText)); } else if ("matched_name_children".equals(matcher.group(1))) { String field = matcher.group(1); String queryText = matcher.group(2); if (queryText != null && !queryText.isEmpty()) { String guid = speciesLookupService.getGuidForName(queryText.replaceAll("\"", "")); // strip any quotes logger.info("GUID for " + queryText + " = " + guid); if (guid != null && !guid.isEmpty()) { field = "lsid"; queryText = guid; } else { field = "taxon_name"; } } if (StringUtils.containsAny(queryText, CHARS) && !queryText.startsWith("[")) { // quote any text that has spaces or colons but not range queries queryText = QUOTE + queryText + QUOTE; } matcher.appendReplacement(queryString, matcher.quoteReplacement(field + ":" + queryText)); } else { matcher.appendReplacement(queryString, matcher.quoteReplacement(value)); } } matcher.appendTail(queryString); query = queryString.toString(); } //if the query string contains lsid: we will need to replace it with the corresponding lft range int last = 0; if (query.contains("lsid:")) { Matcher matcher = lsidPattern.matcher(query); queryString.setLength(0); while (matcher.find()) { //only want to process the "lsid" if it does not represent taxon_concept_lsid etc... if ((matcher.start() > 0 && query.charAt(matcher.start() - 1) != '_') || matcher.start() == 0) { String value = matcher.group(); logger.debug("preprocessing " + value); String lsid = matcher.group(2); if (lsid.contains("\"")) { //remove surrounding quotes, if present lsid = lsid.replaceAll("\"", ""); } if (lsid.contains("\\")) { //remove internal \ chars, if present //noinspection MalformedRegex lsid = lsid.replaceAll("\\\\", ""); } logger.debug("lsid = " + lsid); String[] values = searchUtils.getTaxonSearch(lsid); String lsidHeader = matcher.group(1).length() > 0 ? matcher.group(1) : ""; matcher.appendReplacement(queryString, lsidHeader + values[0]); displaySb.append(query.substring(last, matcher.start())); if (!values[1].startsWith("taxon_concept_lsid:")) displaySb.append(lsidHeader).append("<span class='lsid' id='").append(lsid).append("'>") .append(values[1]).append("</span>"); else displaySb.append(lsidHeader).append(values[1]); last = matcher.end(); //matcher.appendReplacement(displayString, values[1]); } } matcher.appendTail(queryString); displaySb.append(query.substring(last, query.length())); query = queryString.toString(); displayString = displaySb.toString(); } if (query.contains("urn")) { //escape the URN strings before escaping the rest this avoids the issue with attempting to search on a urn field Matcher matcher = urnPattern.matcher(query); queryString.setLength(0); while (matcher.find()) { String value = matcher.group(); logger.debug("escaping lsid urns " + value); matcher.appendReplacement(queryString, prepareSolrStringForReplacement(value)); } matcher.appendTail(queryString); query = queryString.toString(); } if (query.contains("Intersects")) { Matcher matcher = spatialPattern.matcher(query); if (matcher.find()) { String spatial = matcher.group(); SpatialSearchRequestParams subQuery = new SpatialSearchRequestParams(); logger.debug("region Start : " + matcher.regionStart() + " start : " + matcher.start() + " spatial length " + spatial.length() + " query length " + query.length()); //format the search query of the remaining text only subQuery.setQ(query.substring(matcher.start() + spatial.length(), query.length())); //format the remaining query formatSearchQuery(subQuery); //now append Q's together queryString.setLength(0); //need to include the prefix queryString.append(query.substring(0, matcher.start())); queryString.append(spatial); queryString.append(subQuery.getFormattedQuery()); searchParams.setFormattedQuery(queryString.toString()); //add the spatial information to the display string if (spatial.contains("circles")) { String[] values = spatial.substring(spatial.indexOf("=") + 1, spatial.indexOf("}")) .split(","); if (values.length == 3) { displaySb.setLength(0); displaySb.append(subQuery.getDisplayString()); displaySb.append(" - within ").append(values[2]).append(" km of point(") .append(values[0]).append(",").append(values[1]).append(")"); searchParams.setDisplayString(displaySb.toString()); } } else { searchParams.setDisplayString(subQuery.getDisplayString() + " - within supplied region"); } } } else { //escape reserved characters unless the colon represnts a field name colon queryString.setLength(0); Matcher matcher = spacesPattern.matcher(query); while (matcher.find()) { String value = matcher.group(); //special cases to ignore from character escaping //if the value is a single - or * it means that we don't want to escape it as it is likely to have occurred in the following situation -(occurrence_date:[* TO *]) or *:* if (!value.equals("-") && /*!value.equals("*") && !value.equals("*:*") && */ !value.endsWith("*")) { //split on the colon String[] bits = StringUtils.split(value, ":", 2); if (bits.length == 2) { if (!bits[0].contains("urn") && !bits[1].contains("urn\\")) matcher.appendReplacement(queryString, bits[0] + ":" + prepareSolrStringForReplacement(bits[1])); } else if (!value.endsWith(":")) { //need to ignore field names where the : is at the end because the pattern matching will return field_name: as a match when it has a double quoted value //default behaviour is to escape all matcher.appendReplacement(queryString, prepareSolrStringForReplacement(value)); } } } matcher.appendTail(queryString); //substitute better display strings for collection/inst etc searches if (displayString.contains("_uid")) { displaySb.setLength(0); String normalised = displayString.replaceAll("\"", ""); matcher = uidPattern.matcher(normalised); while (matcher.find()) { String newVal = "<span>" + searchUtils.getUidDisplayString(matcher.group(1), matcher.group(2)) + "</span>"; if (newVal != null) matcher.appendReplacement(displaySb, newVal); } matcher.appendTail(displaySb); displayString = displaySb.toString(); } if (searchParams.getQ().equals("*:*")) { displayString = "[all records]"; } if (searchParams.getLat() != null && searchParams.getLon() != null && searchParams.getRadius() != null) { displaySb.setLength(0); displaySb.append(displayString); displaySb.append(" - within ").append(searchParams.getRadius()).append(" km of point(") .append(searchParams.getLat()).append(",").append(searchParams.getLon()).append(")"); displayString = displaySb.toString(); } // substitute i18n version of field name, if found in messages.properties displayString = formatDisplayStringWithI18n(displayString); searchParams.setFormattedQuery(queryString.toString()); logger.debug("formattedQuery = " + queryString); logger.debug("displayString = " + displayString); searchParams.setDisplayString(displayString); } //format the fq's for facets that need ranges substituted for (int i = 0; i < searchParams.getFq().length; i++) { String fq = searchParams.getFq()[i]; String[] parts = fq.split(":", 2); //check to see if the first part is a range based query and update if necessary Map<String, String> titleMap = RangeBasedFacets.getTitleMap(parts[0]); if (titleMap != null) { searchParams.getFq()[i] = titleMap.get(parts[1]); } } } searchParams.setDisplayString(formatDisplayStringWithI18n(searchParams.getDisplayString())); }
From source file:au.org.ala.biocache.dao.SearchDAOImpl.java
/** * Updates the supplied search params to cater for the query context * @param searchParams/* www .j a v a 2 s . com*/ */ protected void updateQueryContext(SearchRequestParams searchParams) { //TODO better method of getting the mappings between qc on solr fields names String qc = searchParams.getQc(); if (StringUtils.isNotEmpty(qc)) { //add the query context to the filter query searchParams.setFq((String[]) ArrayUtils.addAll(searchParams.getFq(), getQueryContextAsArray(qc))); } }
From source file:hybridewah.HybridBitmap.java
public void concatenate(HybridBitmap a) { if (this.verbatim && a.verbatim) { this.buffer = ArrayUtils.addAll(this.buffer, a.buffer); } else if (this.verbatim) { long[] firstWord = new long[] { new Long(this.buffer.length) << 33 }; //first word indicates the number of following literals this.buffer = ArrayUtils.addAll(firstWord, this.buffer); this.buffer = ArrayUtils.addAll(this.buffer, a.buffer); this.verbatim = false; } else if (a.verbatim) { this.buffer = ArrayUtils.add(this.buffer, new Long(a.buffer.length) << 33); this.buffer = ArrayUtils.addAll(this.buffer, a.buffer); } else {//from w w w . j a v a 2 s. co m this.buffer = ArrayUtils.addAll(this.buffer, a.buffer); } this.actualsizeinwords = this.buffer.length; this.density = (this.density * this.sizeinbits + a.density * a.sizeinbits) / (this.sizeinbits + a.sizeinbits); this.sizeinbits = this.sizeinbits + a.sizeinbits; }
From source file:netinf.node.module.MultiLocationPlacement.MLPNodeModule1.java
@Singleton @Provides/*from w w w. ja v a 2 s .c om*/ ResolutionService[] provideResolutionServices(RemoteResolutionFactory remoteResolutionFactory, MDHTResolutionService mdhtResolutionService) { ResolutionService[] otherRS = { mdhtResolutionService }; ResolutionService[] remoteRS = remoteResolutionFactory.getRemoteResolutionServices() .toArray(new ResolutionService[] {}); return (ResolutionService[]) ArrayUtils.addAll(remoteRS, otherRS); }
From source file:netinf.node.module.StandardNodeModule.java
/** * This method provides all the {@link ResolutionService}s which are automatically inserted into the node. In order to get an * instance of the according {@link ResolutionService}, add an additional parameter to this method, since this puts GUICE in * charge of creating the correct instance of the according service. * /*from www .ja v a 2 s. c om*/ * @param localResolutionService * @param rdfResolutionService * @return */ @Singleton @Provides ResolutionService[] provideResolutionServices(RemoteResolutionFactory remoteResolutionFactory, RDFResolutionService rdfResolutionService) { ResolutionService[] otherRS = { rdfResolutionService }; ResolutionService[] remoteRS = remoteResolutionFactory.getRemoteResolutionServices() .toArray(new ResolutionService[] {}); return (ResolutionService[]) ArrayUtils.addAll(remoteRS, otherRS); }
From source file:nl.intercommit.weaves.components.Modal.java
void beginRender(MarkupWriter writer) { if (isDisabled()) return;/* www.j a v a2s. c om*/ final Link link = resources.createEventLink("fetchModalContent", ArrayUtils.addAll(new Object[] { _modalId, _generatedZoneID }, context)); writeLink(writer, link); if (_generatedZoneID != null) { if (!request.isXHR()) writer.getElement().forceAttributes(MarkupConstants.ONCLICK, MarkupConstants.WAIT_FOR_PAGE); cbs.linkZone(getClientId(), _generatedZoneID, link); } }