List of usage examples for org.apache.commons.lang3 StringUtils strip
public static String strip(final String str)
Strips whitespace from the start and end of a String.
This is similar to #trim(String) but removes whitespace.
From source file:org.xlrnet.metadict.engines.heinzelnisse.HeinzelnisseEngine.java
private void extractVerbForms(@NotNull String otherInformation, @NotNull DictionaryObjectBuilder builder) { for (String s : StringUtils.split(otherInformation, ',')) { String flectedForm = StringUtils.strip(StringUtils.substringAfter(s, ":")); if (StringUtils.contains(s, "presens:")) { builder.setAdditionalForm(GrammaticalTense.PRESENT_TENSE, flectedForm); }/*from w w w.j a v a2 s . c o m*/ if (StringUtils.contains(s, "preteritum:")) { builder.setAdditionalForm(GrammaticalTense.PAST_TENSE, flectedForm); } if (StringUtils.contains(s, "partisipp perfekt:")) { builder.setAdditionalForm(GrammaticalTense.PERFECT_PARTICIPLE, flectedForm); } } }
From source file:org.xlrnet.metadict.engines.nobordbok.OrdbokEngine.java
@NotNull private Optional<MonolingualEntry> processTableRow(@NotNull Element tableRow, @NotNull Language language) { MonolingualEntryBuilder entryBuilder = ImmutableMonolingualEntry.builder(); DictionaryObjectBuilder objectBuilder = ImmutableDictionaryObject.builder().setLanguage(language); // Extract general form Element oppslagsord = tableRow.getElementsByClass("oppslagsord").first(); if (oppslagsord != null) { extractGeneralForm(objectBuilder, oppslagsord); } else {// w ww .j ava 2 s.co m LOGGER.warn("Unable to find main element - skipping entry."); return Optional.empty(); } // Extract wordclass and determine entrytype String wordClass = tableRow.getElementsByClass("oppsgramordklasse").first().text(); entryBuilder.setEntryType(resolveEntryTypeWithWordClass(wordClass)); // Get meanings Elements meaningCandidates = tableRow.select(".artikkelinnhold > .utvidet > .tyding"); if (meaningCandidates.size() == 0) meaningCandidates = tableRow.select(".artikkelinnhold > .utvidet"); meaningCandidates.forEach(e -> { String meaning = e.childNodes().stream() .filter(node -> (node instanceof TextNode) || (!((Element) node).hasClass("doemeliste") && !node.hasAttr("style") && !((Element) node).hasClass("utvidet") && !((Element) node).hasClass("artikkelinnhold") && !((Element) node).hasClass("kompakt"))) .map((Node n) -> { if (n instanceof Element) return ((Element) n).text(); else return n.toString(); }).collect(Collectors.joining()); meaning = StringEscapeUtils.unescapeHtml4(meaning); meaning = StringUtils.strip(meaning); if (StringUtils.isNotBlank(meaning)) objectBuilder.addMeaning(meaning); }); entryBuilder.setContent(objectBuilder.build()); return Optional.of(entryBuilder.build()); }
From source file:org.xlrnet.metadict.engines.woxikon.WoxikonEngine.java
@NotNull private DictionaryObject processSingleNode(@NotNull Element element, @NotNull Language language, String queryString) {//from w w w . j av a 2 s.c o m DictionaryObjectBuilder objectBuilder = ImmutableDictionaryObject.builder(); objectBuilder.setLanguage(language); // Extract entry text: String context = StringUtils.substringBefore(element.text(), element.getElementsByTag("a").first().text()); String generalForm = context + element.getElementsByTag("a").first().text(); objectBuilder.setGeneralForm(StringUtils.strip(generalForm)); // Extract description: extractDescription(element, queryString, objectBuilder); // Extract gender: extractGender(element, objectBuilder); return objectBuilder.build(); }
From source file:org.xlrnet.metadict.engines.woxikon.WoxikonEngine.java
private void extractDescription(@NotNull Element element, String queryString, DictionaryObjectBuilder objectBuilder) { Element descriptionNode = element.getElementsByClass(CLASS_DESCRIPTION).first(); if (descriptionNode == null) { // Try to detect the description node with an alternative class (necessary for synonyms) descriptionNode = element.getElementsByClass(CLASS_EXTRA_INFO).first(); }// www. j a v a 2 s . co m if (descriptionNode != null) { String description = descriptionNode.text(); description = StringUtils.removeStart(description, DESCRIPTION_BEGIN); description = StringUtils.removeEnd(description, DESCRIPTION_END); if (!StringUtils.equalsIgnoreCase(description, queryString)) // Set description only if it is different from request string objectBuilder.setDescription(StringUtils.strip(description)); } }
From source file:org.yasmin.core.config.parser.CommentToken.java
@Override public IYasminConfigToken parse(String line) { if (StringUtils.strip(line).startsWith(COMMENT_PREFIX)) { return new CommentToken(line); }//from w ww .jav a 2 s . co m return null; }
From source file:org.yasmin.core.config.parser.KeyValueToken.java
/** * Checks if the given line is a valid keypair line. * //from w w w .ja v a 2 s .c om * @param line * The line to be verified * @return <code>true</code> if the line is a valid keypair line. */ private boolean isValid(String line) { if (!Character.isAlphabetic(line.charAt(0))) { return false; } // Line must not end with { if (StringUtils.strip(line).endsWith("{")) { return false; } int equalIndex = line.indexOf("="); // Starts with a character... it must have an equal sign... if (equalIndex == -1) { return false; } // Equal sign found... Let's validate the key... String keyName = line.substring(0, equalIndex); if (!keyName.matches(KEY_REGEX)) { return false; } return true; }
From source file:ubic.basecode.ontology.search.OntologySearch.java
/** * Will remove characters that jena is unable to parse. Will also escape and remove leading and trailing white space * (which also causes jena to die)//from www . ja va2 s . c o m * * @param toStrip the string to clean * @return */ public static String stripInvalidCharacters(String toStrip) { String result = StringUtils.strip(toStrip); for (char badChar : INVALID_CHARS) { result = StringUtils.remove(result, badChar); } /* * Queries cannot start with '*' or ? */ result = result.replaceAll("^\\**", ""); result = result.replaceAll("^\\?*", ""); return StringEscapeUtils.escapeJava(result).trim(); }
From source file:ubic.basecode.ontology.search.OntologySearch.java
/** * @param model/* w w w. j a v a 2s . com*/ * @param index * @param queryString * @return */ private static NodeIterator runSearch(SearchIndex index, String queryString) { String strippedQuery = StringUtils.strip(queryString); if (StringUtils.isBlank(strippedQuery)) { throw new IllegalArgumentException("Query cannot be blank"); } String query = queryString.replaceAll(" AND ", " "); List<String> list = new ArrayList<>(); Matcher m = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(query); while (m.find()) { list.add(m.group(1)); } String enhancedQuery = StringUtils.join(list, " " + Operator.AND + " "); /* * Note that LARQ does not allow you to change the default operator without making it non-thread-safe. */ try { StopWatch timer = new StopWatch(); timer.start(); index.getLuceneQueryParser().setDefaultOperator(Operator.AND); NodeIterator iterator = index.searchModelByIndex(enhancedQuery); if (timer.getTime() > 100) { log.info("Ontology resource search for: " + queryString + " (parsed to: " + enhancedQuery + ") : " + timer.getTime() + "ms"); } return iterator; } catch (ARQException e) { // index is closed? log.error("Error while searching: " + e.getMessage(), e); return null; } }
From source file:ubic.gemma.core.apps.GenericGenelistDesignGenerator.java
private String generateShortName() { String ncbiIdSuffix = useNCBIIds ? "_ncbiIds" : ""; String ensemblIdSuffix = useEnsemblIds ? "_ensemblIds" : ""; String shortName;//from w ww.ja v a 2s . c o m if (StringUtils.isBlank(taxon.getCommonName())) { shortName = "Generic_" + StringUtils.strip(taxon.getScientificName()).replaceAll(" ", "_") + ncbiIdSuffix; } else { shortName = "Generic_" + StringUtils.strip(taxon.getCommonName()).replaceAll(" ", "_") + ncbiIdSuffix + ensemblIdSuffix; } return shortName; }
From source file:ubic.gemma.core.apps.LoadExpressionDataCli.java
@Override protected Exception doWork(String[] args) { Exception err = this.processCommandLine(args); if (err != null) { return err; }/*from w ww .j a v a2 s . co m*/ try { GeoService geoService = this.getBean(GeoService.class); geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGenerator()); if (accessions == null && accessionFile == null) { return new IllegalArgumentException( "You must specific either a file or accessions on the command line"); } if (accessions != null) { AbstractCLI.log.info("Got accession(s) from command line " + accessions); String[] accsToRun = StringUtils.split(accessions, ','); for (String accession : accsToRun) { accession = StringUtils.strip(accession); if (StringUtils.isBlank(accession)) { continue; } if (platformOnly) { Collection<?> designs = geoService.fetchAndLoad(accession, true, true, false, true, true); ArrayDesignService ads = this.getBean(ArrayDesignService.class); for (Object object : designs) { assert object instanceof ArrayDesign; ArrayDesign ad = (ArrayDesign) object; ad = ads.thawLite(ad); successObjects.add(ad.getName() + " (" + ad.getExternalReferences().iterator().next().getAccession() + ")"); } } else { this.processAccession(geoService, accession); } } } if (accessionFile != null) { AbstractCLI.log.info("Loading accessions from " + accessionFile); InputStream is = new FileInputStream(accessionFile); try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { String accession; while ((accession = br.readLine()) != null) { if (StringUtils.isBlank(accession)) { continue; } this.processAccession(geoService, accession); } } } this.summarizeProcessing(); } catch (Exception e) { AbstractCLI.log.error(e); return e; } return null; }