Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (C) 2009 Anton Karl Ingason
 *
 * This file is part of the IceNLP toolkit.
 * IceNLP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * IceNLP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with IceNLP. If not,  see <http://www.gnu.org/licenses/>.
 *
 * Contact information:
 * Anton Karl Ingason, University of Iceland.
 * anton.karl.ingason@gmail.com
 */

public class Main {
    public static String createBestMapping(String wordForm, String lemma) {

        String mapping = wordForm + ">" + lemma;
        // Find longest start match
        int minLen = Math.min(wordForm.length(), lemma.length());
        if (wordForm.charAt(0) == lemma.charAt(0)) {

            String wordFormStart = wordForm.substring(0, minLen - 1);
            String lemmaStart = lemma.substring(0, minLen - 1);

            String wordFormEnd;
            String lemmaEnd;

            while (!wordFormStart.equals(lemmaStart)) {
                wordFormStart = wordFormStart.substring(0, wordFormStart.length() - 1);
                lemmaStart = lemmaStart.substring(0, lemmaStart.length() - 1);
            }

            wordFormEnd = wordForm.substring(lemmaStart.length());
            lemmaEnd = lemma.substring(lemmaStart.length());

            mapping = wordFormEnd + ">" + lemmaEnd;
        }

        return mapping;
    }
}