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.4.7 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.4.6 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.4.5 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.4.4 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.4.3 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.4.2 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.4.1 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.4.0 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.3.3 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.3.2 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.3.1 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.3.0 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.2.3 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.2.2 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.2.1 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.2.0 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.1.5 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.1.4 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.1.3 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java
abstractor-4.1.2 lib/lingscope/src/lingscope/algorithms/negex/Sorter.java