lv.semti.morphology.webservice.TransliterationResource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webservices Show documentation
Show all versions of webservices Show documentation
Webservice API for Tēzaurs.lv and other ailab.lv Latvian computational linguistic tools
/*******************************************************************************
* Copyright 2012, 2013, 2014 Institute of Mathematics and Computer Science, University of Latvia
* Author: Pēteris Paikens
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*******************************************************************************/
package lv.semti.morphology.webservice;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import lv.ailab.lnb.fraktur.translit.ResultData;
public class TransliterationResource extends ServerResource {
@Get("xml")
public String retrieve() {
getResponse().setAccessControlAllowOrigin("*");
String ruleset = (String) getRequest().getAttributes().get("ruleset");
String word = (String) getRequest().getAttributes().get("word");
try {
word = URLDecoder.decode(word, "UTF8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String XML = "";
try {
if (!MorphoServer.translit.isValidRuleSet(ruleset)) {
// Fallback
ruleset = "core";
}
XML += "";
ResultData rd = MorphoServer.translit.processWord(word, ruleset, true);
if (rd != null) {
XML += rd.toXML(MorphoServer.translit.getDictIdKey(),
MorphoServer.translit.getEntryUrlKey(),
MorphoServer.translit.comparator);
}
XML += " ";
} catch (Exception e) {
e.printStackTrace();
}
return XML;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy