Example usage for org.apache.commons.lang StringUtils isAllLowerCase

List of usage examples for org.apache.commons.lang StringUtils isAllLowerCase

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils isAllLowerCase.

Prototype

public static boolean isAllLowerCase(String str) 

Source Link

Document

Checks if the String contains only lowercase characters.

Usage

From source file:ips1ap101.lib.base.util.StrUtils.java

public static boolean isMixedCase(String string) {
    return !StringUtils.isAllLowerCase(string) && !StringUtils.isAllUpperCase(string);
}

From source file:ips1ap101.lib.base.util.StrUtils.java

public static boolean isNotMixedCase(String string) {
    return StringUtils.isAllLowerCase(string) || StringUtils.isAllUpperCase(string);
}

From source file:adalid.commons.util.StrUtils.java

public static boolean isNotMixedCase(String string) {
    string = StringUtils.trimToEmpty(string);
    if (string.isEmpty()) {
        return true;
    }/*from ww  w  . j ava 2s. com*/
    string = string.replaceAll("[^a-zA-Z]", "");
    if (string.isEmpty()) {
        return true;
    }
    return StringUtils.isAllLowerCase(string) || StringUtils.isAllUpperCase(string);
}

From source file:org.alfresco.rest.framework.Api.java

/**
 * Creates an valid instance of the Api object
 * @param apiName a String in lowercase//from  www .  java2  s  .  c  o m
 * @param apiScope SCOPE
 * @param apiVersion postive integer
 * @return Api
 */
public static Api valueOf(String apiName, String apiScope, String apiVersion) throws InvalidArgumentException {
    SCOPE scope = null;
    int version = 1;

    try {
        if (!StringUtils.isAllLowerCase(apiName))
            throw new InvalidArgumentException("Api name must be lowercase");
        scope = SCOPE.valueOf(apiScope.toUpperCase());
        version = Integer.parseInt(apiVersion);
        if (version < 1)
            throw new InvalidArgumentException("Version must be a positive integer.");
    } catch (Exception error) {
        if (error instanceof InvalidArgumentException)
            throw (InvalidArgumentException) error; //Just throw it on.
        logger.debug("Invalid API definition: " + apiName + " " + apiScope + " " + apiVersion);
        throw new InvalidArgumentException("Invalid API definition:" + error.getMessage());
    }

    Api anApi = new Api(apiName, scope, version);
    return ALFRESCO_PUBLIC.equals(anApi) ? ALFRESCO_PUBLIC : anApi;

}

From source file:org.dkpro.tc.features.window.CaseExtractor.java

public static String getCasing(String text) {
    if (StringUtils.isNumeric(text))
        return "numeric";
    if (StringUtils.isAllLowerCase(text))
        return "allLower";
    else if (StringUtils.isAllUpperCase(text))
        return "allUpper";
    else if (Character.isUpperCase(text.charAt(0)))
        return "initialUpper";
    else//  ww w .  j av a2  s .  co m
        return "other";
}

From source file:org.mitre.opensextant.extraction.PlacenameMatcher.java

/**
 * Tag a document, returning PlaceCandidates for the mentions in document.
 * Converts a GATE document to a string and passes it to the Solr server via
 * HTTP POST. The tokens and featureName parameters are not used.
 * @param buffer//from  w  w w .j av  a 2s.  c  o m
 * @param docid
 *
 * @return place_candidates List of place candidates
 * @throws MatcherException
 */
public List<PlaceCandidate> tagText(String buffer, String docid) throws MatcherException {
    // "tagsCount":10, "tags":[{ "ids":[35], "endOffset":40, "startOffset":38},
    // { "ids":[750308, 2769912, 2770041, 10413973, 10417546], "endOffset":49,
    // "startOffset":41},
    // ...
    // "matchingDocs":{"numFound":75, "start":0, "docs":[ {
    // "place_id":"USGS1992921", "name":"Monterrey", "cc":"PR"}, {
    //"place_id":"USGS1991763", "name":"Monterrey", "cc":"PR"}, ]   

    if (debug) {
        log.debug("TEXT SIZE = " + buffer.length());
    }

    List<PlaceCandidate> candidates = new ArrayList<>();

    // Setup request to tag... 
    tag_request.input = buffer;
    QueryResponse response = null;
    try {
        response = tag_request.process(solr.getInternalSolrServer());
    } catch (Exception err) {
        throw new MatcherException("Failed to tag document=" + docid, err);
    }

    // -- Process Solr Response

    //List<GeoBean> geoBeans = response.getBeans(GeoBean.class); maybe works but probably slow
    SolrDocumentList docList = (SolrDocumentList) response.getResponse().get("matchingDocs");
    beanMap.clear();
    String name = null;
    for (SolrDocument solrDoc : docList) {

        name = SolrProxy.getString(solrDoc, "name");
        if (filter.filterOut(name.toLowerCase())) {
            continue;
        }

        Place bean = new Place();

        bean.setName_type(SolrProxy.getChar(solrDoc, "name_type"));

        // Gazetteer place name & country:
        //   NOTE: this may be different than "matchtext" or PlaceCandidate.name field.
        // 
        bean.setPlaceName(name);
        bean.setCountryCode(SolrProxy.getString(solrDoc, "cc"));

        // Other metadata.
        bean.setAdmin1(SolrProxy.getString(solrDoc, "adm1"));
        bean.setAdmin2(SolrProxy.getString(solrDoc, "adm2"));
        bean.setFeatureClass(SolrProxy.getString(solrDoc, "feat_class"));
        bean.setFeatureCode(SolrProxy.getString(solrDoc, "feat_code"));
        bean.setLatitude(SolrProxy.getDouble(solrDoc, "lat"));
        bean.setLongitude(SolrProxy.getDouble(solrDoc, "lon"));

        bean.setPlaceID(SolrProxy.getString(solrDoc, "place_id"));
        bean.setName_bias(SolrProxy.getDouble(solrDoc, "name_bias"));
        bean.setId_bias(SolrProxy.getDouble(solrDoc, "id_bias"));

        // Hashed on "id"
        Integer id = (Integer) solrDoc.getFirstValue("id");
        beanMap.put(id, bean);
    }

    @SuppressWarnings("unchecked")
    List<NamedList<?>> tags = (List<NamedList<?>>) response.getResponse().get("tags");

    if (debug) {
        log.debug("DOC=" + docid + " TAGS SIZE = " + tags.size());
    }

    /*
     * Retrieve all offsets into a long list.  These offsets will report
     * a text span and all the gazetteer record IDs that are associated to that span.
     * The text could either be a name, a code or some other abbreviation.
     * 
     * For practical reasons the default behavior is to filter trivial spans given 
     * the gazetteer data that is returned for them.
     * 
     * WARNING: lots of optimizations occur here due to the potentially large volume of tags
     * and gazetteer data that is involved.  And this is relatively early in the pipline.
     * 
     */
    PlaceCandidate pc;
    Place Pgeo;
    int x1 = -1, x2 = -1;
    Set<String> seenPlaces = new HashSet<>();
    Double name_bias = 0.0;

    String matchText = null;
    for (NamedList<?> tag : tags) {
        x1 = (Integer) tag.get("startOffset");
        x2 = (Integer) tag.get("endOffset");//+1 char after last matched
        matchText = buffer.substring(x1, x2);

        /**
         * We can filter out trivial place name matches that we know to be
         * close to false positives 100% of the time. E.g,. "way", "back",
         * "north" You might consider two different stop filters, Is "North"
         * different than "north"? This first pass filter should really
         * filter out only text we know to be false positives regardless of
         * case.
         */
        if (filter.filterOut(matchText.toLowerCase())) {
            continue;
        }

        pc = new PlaceCandidate();
        pc.setStart(x1);
        pc.setEnd(x2);

        // Could have enabled the "matchText" option from the tagger to get
        // this, but since we already have the content as a String then
        // we might as well not make the tagger do any more work.
        pc.setPlaceName(matchText); //
        name_bias = 0.0;

        @SuppressWarnings("unchecked")
        List<Integer> placeRecordIds = (List<Integer>) tag.get("ids");
        //clear out places seen for the next candidate
        seenPlaces.clear();
        boolean _is_valid = true;
        boolean _is_lower = StringUtils.isAllLowerCase(pc.getText());

        for (Integer solrId : placeRecordIds) {
            Pgeo = beanMap.get(solrId);
            if (Pgeo == null) {
                if (debug) {
                    log.debug("Logic error. Did not find place object for Solr ID=" + solrId);
                }
                continue;
            }

            // Optimization:  abbreviation filter.
            // 
            // Do not add PlaceCandidates for lower case tokens that are marked as Abbreviations
            // Unless flagged to do so.
            // DEFAULT behavior is to avoid lower case text that is tagged as an abbreviation in gazetteer,
            // 
            // Common terms:  in, or, oh, me, us, we, 
            //   etc.
            // Are all not typically place names or valid abbreviations in text.
            //                 
            if (!allow_lowercase_abbrev) {
                if (Pgeo.isAbbreviation() && _is_lower) {
                    _is_valid = false;
                    if (debug) {
                        log.debug("Ignore lower case term=" + pc.getText());
                    }

                    break;
                }

            }
            // Optimization: Add distinct place objects once. 
            //   don't add Place if null or already added to this instance of PlaceCandidate
            // 
            if (!seenPlaces.contains(Pgeo.getPlaceID())) {
                pc.addPlace(Pgeo);
                seenPlaces.add(Pgeo.getPlaceID());

                // get max name bias
                Double n_bias = Pgeo.getName_bias();
                if (n_bias > name_bias) {
                    name_bias = n_bias;
                }
            }

            // Indeed this does happen.
            // else { log.info("Does this ever happen -- ? " + pc.getText() + " " + Pgeo.getPlaceName()); }
        }

        /**
         * Some rule above triggered a flag that indicates this
         * token/place/name is not valid.
         *
         */
        if (!_is_valid) {
            continue;
        }

        // if the max name bias seen >0; add apriori evidence
        if (name_bias != 0.0) {
            pc.addRuleAndConfidence(APRIORI_NAME_RULE, name_bias);
        }

        candidates.add(pc);
    }

    if (debug) {
        summarizeExtraction(candidates, docid);
    }

    return candidates;
}

From source file:org.sonar.plugins.gosu.codenarc.apt.AptParser.java

private static String getRuleName(String line) {
    if (StringUtils.isBlank(line)) {
        return null;
    }/*  w w  w  . j  a va2 s . c om*/
    String result = null;
    if (line.startsWith("* {")) {
        result = StringUtils.substringBetween(line, "* {", "} Rule").trim();
    } else {
        result = line.substring(2).trim();
    }
    if (result.endsWith("Rule")) {
        result = result.substring(0, result.length() - 4);
    }
    if (StringUtils.isAllLowerCase(result) || !StringUtils.isAlphanumeric(result)
            || "References".equals(result)) {
        // false positive
        return null;
    }
    return result;
}

From source file:org.sonar.server.es.NewIndex.java

NewIndex(String indexName) {
    Preconditions.checkArgument(StringUtils.isAllLowerCase(indexName),
            "Index name must be lower-case: " + indexName);
    this.indexName = indexName;
}

From source file:org.xcmis.search.lucene.LuceneQueryBuilder.java

/**
 * @see org.xcmis.search.QueryObjectModelVisitor#visit(org.xcmis.search.model.operand.LowerCase)
 *//*from  w  ww  .j a v a2 s.c  o  m*/

public void visit(LowerCase node) throws VisitException {
    Validate.isTrue(queryBuilderStack.peek() instanceof Boolean,
            "Stack should contains caseInsensitiveSearch flag");
    boolean caseInsensitiveSearch = (Boolean) queryBuilderStack.pop();

    final String value = (String) queryBuilderStack.peek();
    if (!caseInsensitiveSearch && !StringUtils.isAllLowerCase(value)) {
        // search nothing because static value in different case
        queryBuilderStack.push(new BooleanQuery());
    }

    queryBuilderStack.push(new Boolean(true));
    // push dynamic query to stack;
    Visitors.visit(node.getOperand(), this);
}