// Path: src/main/java/org/oscii/concordance/PhrasalRule.java
// public class PhrasalRule {
//   List<String> sourceWords;
//   List<String> targetWords;
//   double score = 0.0;
// 
//   public PhrasalRule(String sourcePhrase, String targetPhrase, double score) {
//     this.sourceWords = splitPhrase(sourcePhrase);
//     this.targetWords = splitPhrase(targetPhrase);
//     this.score = score;
//   }
// 
//   public String getSource() {
//     return String.join(" ", sourceWords);
//   }
// 
//   public String getTarget() {
//     return String.join(" ", targetWords);
//   }
// 
//   public double getScore() {
//     return score;
//   }
// 
//   private static List<String> splitPhrase(String phrase) {
//     if (phrase == null) {
//       return Collections.emptyList();
//     } else {
//       return Arrays.asList(phrase.split("\\s+"));
//     }
//   }
// }
// 
// Path: src/main/java/org/oscii/concordance/SentenceExample.java
// public class SentenceExample {
// 
//   final public AlignedSentence sentence;
//   final public int sourceStart, sourceLength, targetStart, targetLength;
//   public double similarity; // Word2Vec similarity to request.context
//   public int memoryId; // indicates a foreground (<=0) vs. background TM match (-1)
// 
//   public SentenceExample(AlignedSentence sentence, int sourceStart, int sourceLength, int targetStart, int targetLength, int memoryId) {
//     this.sentence = sentence;
//     this.sourceStart = sourceStart;
//     this.sourceLength = sourceLength;
//     this.targetStart = targetStart;
//     this.targetLength = targetLength;
//     this.similarity = 0.0;
//     this.memoryId = memoryId;
//   }
// 
//   public SentenceExample(AlignedSentence sentence, int sourceStart, int sourceLength, int targetStart, int targetLength, int memoryId, double similarity) {
//     this(sentence, sourceStart, sourceLength, targetStart, targetLength, memoryId);
//     this.similarity = similarity;
//   }
// 
//   public static SentenceExample create(AlignedSentence s, int sourceStart, int sourceLength, int memoryId) {
//     int targetMin = s.aligned.tokens.length;
//     int targetMax = -1;
//     for (int i = sourceStart; i < sourceStart + sourceLength; i++) {
//       int[] a = s.getAlignment()[i];
//       for (int j : a) {
//         if (j < targetMin) targetMin = j;
//         if (j > targetMax) targetMax = j;
//       }
//     }
//     if (targetMax == -1) {
//       targetMin = 0;
//     }
//     return new SentenceExample(s, sourceStart, sourceLength, targetMin, targetMax - targetMin + 1, memoryId);
//   }
// }


import org.oscii.concordance.PhrasalRule;
import org.oscii.concordance.SentenceExample;
import java.util.Comparator;
package org.oscii.lex;



/**
 * Ordering on lexical items
 */
public class Order {
    public static final Comparator<? super Translation> byFrequency = new Comparator<Translation>() {
        @Override
        public int compare(Translation o1, Translation o2) {
            return Double.compare(o2.frequency, o1.frequency);
        }
    };

    public static final Comparator<? super Meaning> byMaxTranslationFrequency = new Comparator<Meaning>() {
        @Override
        public int compare(Meaning o1, Meaning o2) {
            if (o2.translations.size() == 0) {
                return -1;
            } else if (o1.translations.size() == 0) {
                return 1;
            } else {
                return Double.compare(
                        o2.translations.get(0).frequency,
                        o1.translations.get(0).frequency);
            }
        }
    };

    public static final Comparator<? super Expression> byLength = new Comparator<Expression>() {
        @Override
        public int compare(Expression o1, Expression o2) {
            return o1.text.length() - o2.text.length();
        }
    };

// Path: src/main/java/org/oscii/concordance/PhrasalRule.java
// public class PhrasalRule {
//   List<String> sourceWords;
//   List<String> targetWords;
//   double score = 0.0;
// 
//   public PhrasalRule(String sourcePhrase, String targetPhrase, double score) {
//     this.sourceWords = splitPhrase(sourcePhrase);
//     this.targetWords = splitPhrase(targetPhrase);
//     this.score = score;
//   }
// 
//   public String getSource() {
//     return String.join(" ", sourceWords);
//   }
// 
//   public String getTarget() {
//     return String.join(" ", targetWords);
//   }
// 
//   public double getScore() {
//     return score;
//   }
// 
//   private static List<String> splitPhrase(String phrase) {
//     if (phrase == null) {
//       return Collections.emptyList();
//     } else {
//       return Arrays.asList(phrase.split("\\s+"));
//     }
//   }
// }
// 
// Path: src/main/java/org/oscii/concordance/SentenceExample.java
// public class SentenceExample {
// 
//   final public AlignedSentence sentence;
//   final public int sourceStart, sourceLength, targetStart, targetLength;
//   public double similarity; // Word2Vec similarity to request.context
//   public int memoryId; // indicates a foreground (<=0) vs. background TM match (-1)
// 
//   public SentenceExample(AlignedSentence sentence, int sourceStart, int sourceLength, int targetStart, int targetLength, int memoryId) {
//     this.sentence = sentence;
//     this.sourceStart = sourceStart;
//     this.sourceLength = sourceLength;
//     this.targetStart = targetStart;
//     this.targetLength = targetLength;
//     this.similarity = 0.0;
//     this.memoryId = memoryId;
//   }
// 
//   public SentenceExample(AlignedSentence sentence, int sourceStart, int sourceLength, int targetStart, int targetLength, int memoryId, double similarity) {
//     this(sentence, sourceStart, sourceLength, targetStart, targetLength, memoryId);
//     this.similarity = similarity;
//   }
// 
//   public static SentenceExample create(AlignedSentence s, int sourceStart, int sourceLength, int memoryId) {
//     int targetMin = s.aligned.tokens.length;
//     int targetMax = -1;
//     for (int i = sourceStart; i < sourceStart + sourceLength; i++) {
//       int[] a = s.getAlignment()[i];
//       for (int j : a) {
//         if (j < targetMin) targetMin = j;
//         if (j > targetMax) targetMax = j;
//       }
//     }
//     if (targetMax == -1) {
//       targetMin = 0;
//     }
//     return new SentenceExample(s, sourceStart, sourceLength, targetMin, targetMax - targetMin + 1, memoryId);
//   }
// }


// Path: src/main/java/org/oscii/lex/Order.java
import org.oscii.concordance.PhrasalRule;
import org.oscii.concordance.SentenceExample;
import java.util.Comparator;

package org.oscii.lex;



/**
 * Ordering on lexical items
 */
public class Order {
    public static final Comparator<? super Translation> byFrequency = new Comparator<Translation>() {
        @Override
        public int compare(Translation o1, Translation o2) {
            return Double.compare(o2.frequency, o1.frequency);
        }
    };

    public static final Comparator<? super Meaning> byMaxTranslationFrequency = new Comparator<Meaning>() {
        @Override
        public int compare(Meaning o1, Meaning o2) {
            if (o2.translations.size() == 0) {
                return -1;
            } else if (o1.translations.size() == 0) {
                return 1;
            } else {
                return Double.compare(
                        o2.translations.get(0).frequency,
                        o1.translations.get(0).frequency);
            }
        }
    };

    public static final Comparator<? super Expression> byLength = new Comparator<Expression>() {
        @Override
        public int compare(Expression o1, Expression o2) {
            return o1.text.length() - o2.text.length();
        }
    };

    public static final Comparator<? super PhrasalRule> byScore = new Comparator<PhrasalRule>() {