Sha256: ff8295f67a50d669f89fb79e14b67adafe475c714d3466df1671237c58b2f67e

Contents?: true

Size: 1.19 KB

Versions: 45

Compression:

Stored size: 1.19 KB

Contents

package lingscope.algorithms.negex;

import java.util.*;

// Utility class to sort the negation rules by length in descending order.
// Rules need to be matched by longest first because there is overlap between the
// RegEx of the rules.
//
// Author: Imre Solti
// solti@u.washington.edu
// Date: 10/20/2008
public class Sorter {

    public List<String> sortRules(List<String> unsortedRules) {

        try {
            // Sort the negation rules by length to make sure
            // that longest rules match first.
            String temp = "";
            for (int i = 0; i < unsortedRules.size() - 1; i++) {
                for (int j = i + 1; j < unsortedRules.size(); j++) {
                    String a = (String) unsortedRules.get(i);
                    String b = (String) unsortedRules.get(j);
                    if (a.trim().length() < b.trim().length()) {
                        // Sorting into descending order by lebgth of string.
                        unsortedRules.set(i, b);
                        unsortedRules.set(j, a);
                    }
                }
            }
        } catch (Exception e) {
            System.out.println(e);
        }
        return unsortedRules;
    }
}

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
abstractor-4.1.1 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.1.0 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.0.2 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.0.1 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.0.0 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-2.1.2 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-2.1.01 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-2.1.0 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-2.0.1 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-2.0.0 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-1.0.23 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-1.0.22 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-1.0.20 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-1.0.19 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-1.0.18 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-1.0.17 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-1.0.16 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-1.0.15 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-1.0.14 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-1.0.13 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java