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

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

Introduction

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

Prototype

public static String abbreviate(String str, int maxWidth) 

Source Link

Document

Abbreviates a String using ellipses.

Usage

From source file:de.tudarmstadt.lt.n2n.preparsed.annotators.PreParsedLineAnnotator.java

@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
    try {//from   w  ww .  j  ava2s  .  co m
        _parser.parse(aJCas, _create_sentences, _create_tokens, _create_dependencies,
                _create_collapsed_dependencies, _create_constituents, _write_penntree);
    } catch (Exception e) {
        LOG.warn("Could not process cas {}, text: '{}' ({}: {})", DocumentMetaData.get(aJCas).getDocumentId(),
                StringUtils.abbreviate(aJCas.getDocumentText(), 50), e.getClass().getSimpleName(),
                e.getMessage());
        if (_fail_early)
            throw new AnalysisEngineProcessException(e);
    }
}

From source file:com.fortify.processrunner.octane.processor.ProcessorOctaneSubmitIssueForVulnerabilities.java

@Override
protected SubmittedIssue submitIssue(Context context, LinkedHashMap<String, Object> issueData) {
    IContextOctane contextOctane = context.as(IContextOctane.class);
    OctaneAuthenticatingRestConnection conn = OctaneConnectionFactory.getConnection(context);
    issueData.put("name", StringUtils.abbreviate((String) issueData.get("name"), 254));
    return conn.submitIssue(new OctaneSharedSpaceAndWorkspaceId(contextOctane.getOctaneSharedSpaceUid(),
            contextOctane.getOctaneWorkspaceId()), issueData);
}

From source file:mobi.chouette.model.Network.java

/**
 * set description <br/>//  ww w  . j av a2  s .c o m
 * truncated to 255 characters if too long
 * 
 * @param value
 *            New value
 */
public void setDescription(String value) {
    description = StringUtils.abbreviate(value, 255);
}

From source file:edu.txstate.dmlab.clusteringwiki.cluster.KMeansClusterer.java

/**
 * Choose initial seeds.  Should be called after setting
 * numClusters and documentsToCluster./*w ww.j  a v  a  2 s  .  c om*/
 * @return array of initial centroid/seed vectors
 */
protected List<IClusterDocument> chooseSeeds(String parentId) {
    if (documentsToCluster == null || documentsToCluster.length == 0)
        throw new IllegalArgumentException("Documents cannot be empty");
    if (numClusters < 0 || numClusters > documentsToCluster.length)
        throw new IllegalArgumentException("Invalid number of clusters");

    //prepare container for the seeds
    List<IClusterDocument> seeds = new ArrayList<IClusterDocument>(numClusters);
    //first order the docs by URL
    Map<String, Integer> orderedDocs = new TreeMap<String, Integer>();
    for (int i : documentsToCluster) {
        IClusterDocument d = allDocs.get(i);
        String key = StringUtils.abbreviate(d.getResultDoc().getUrl(), 20) + d.getIndex();
        orderedDocs.put(key, d.getIndex());
    }
    Integer[] orderedDocIds = new Integer[orderedDocs.size()];
    orderedDocs.values().toArray(orderedDocIds);

    //then choose distributed values
    List<Integer> chosen = new ArrayList<Integer>();
    int i = 1;
    int n = orderedDocs.size();
    if (n > 1) {
        //choose a
        int a = n / 10 - 1;
        while (a < 0 || a % n == 0)
            a++;
        //choose cluster seeds
        while (chosen.size() < numClusters) {
            int c = (a * i) % n;
            if (!chosen.contains(c))
                chosen.add(c);
            i++;
        }
    } else {
        chosen.add(0);
    }

    Integer[] chosenSeeds = new Integer[chosen.size()];
    int m = 0;
    //retrieve the seeds according to the computed distribution
    for (int c : chosen) {
        seeds.add(allDocs.get(orderedDocIds[c]));
        chosenSeeds[m++] = orderedDocIds[c];
    }

    return seeds;
}

From source file:de.tudarmstadt.lt.lm.service.LtSegProvider.java

@Override
public List<String> splitSentences(String text, String language_code) throws Exception {
    LOG.trace(String.format("Splitting sentences from text: %s", StringUtils.abbreviate(text, 200)));
    List<String> sentences = new ArrayList<String>();

    if (Properties.onedocperline()) {
        LineIterator liter = new LineIterator(new StringReader(text));
        for (String line; (line = liter.hasNext() ? liter.next() : null) != null;)
            split_and_add_sentences(line, sentences);
    } else {/*from w  w w. ja va2 s  .  c  o m*/
        split_and_add_sentences(text, sentences);
    }

    LOG.trace(String.format("Split text '%s' into '%d' sentences.", StringUtils.abbreviate(text, 200),
            sentences.size()));
    return sentences;
}

From source file:de.tudarmstadt.lt.n2n.preparsed.annotators.GoogleSyntacticNgramsAnnotator.java

void parseCasLines(JCas aJCas) {
    DocumentMetaData metadata = DocumentMetaData.get(aJCas);
    String cas_id = metadata.getDocumentId();
    String cas_text = aJCas.getDocumentText();
    LOG.trace("[{}] Splitting text into lines '{}'.", cas_id, StringUtils.abbreviate(cas_text, 50));
    if (cas_text.trim().isEmpty()) {
        LOG.trace("[{}] Text is empty.", cas_id);
        return;/*from   w ww  .ja va2s  .c o  m*/
    }

    List<Integer> line_idxs = new ArrayList<Integer>();
    line_idxs.add(0);
    for (int index = 0; (index = cas_text.indexOf('\n', index) + 1) > 0; line_idxs.add(index))
        ;
    LOG.debug("[{}] Found {} newline characters -> {} lines [{}]", cas_id, line_idxs.size(),
            line_idxs.size() + 1, StringUtils.abbreviate(cas_text, 50));
    if (line_idxs.get(line_idxs.size() - 1) < cas_text.length()) // if cas doesn't end with a new line
        line_idxs.add(cas_text.length());

    for (int i = 0; i < line_idxs.size() - 1; i++) {
        int bline_idx = line_idxs.get(i);
        int eline_idx = line_idxs.get(i + 1);
        parseCasLine(aJCas, bline_idx, eline_idx);
    }

}

From source file:mobi.chouette.model.NeptuneLocalizedObject.java

/**
 * set zip code <br/>//ww  w  .ja v a 2s  .  c  om
 * truncated to 255 characters if too long
 * 
 * @param value
 *            New value
 */
public void setZipCode(String value) {
    zipCode = StringUtils.abbreviate(value, 255);
}

From source file:com.sfs.ucm.model.Help.java

/**
 * Short form//from   w  w w.j av  a 2s . c  om
 * 
 * @return the helpContent
 */
public String getContentAbbrv() {
    String content = null;
    if (StringUtils.isNotEmpty(this.content)) {
        content = StringUtils.abbreviate(this.content, 100);
    }
    return content;
}

From source file:de.tudarmstadt.lt.lm.service.UimaStringProvider.java

@Override
public List<String>[] getNgrams(String text, String language_code) throws Exception {
    String docid = "#" + Integer.toHexString(text.hashCode());
    LOG.debug("[{}] Processing text '{}' (length {}).", docid, StringUtils.abbreviate(text, 30), text.length());
    return getNgramsInner(text.trim(), language_code, docid, 0, 0);
}

From source file:mobi.chouette.model.Company.java

/**
 * set organization code <br/>//from  w ww .  j  ava 2 s .c om
 * truncated to 255 characters if too long
 * 
 * @param value
 *            New value
 */
public void setCode(String value) {
    code = StringUtils.abbreviate(value, 255);
}