一、场景

给定一段英文,标记出错误的英文单词。

二、示例

小程序

三、程序

package Nlp;import org.apache.http.HttpEntity;import org.apache.http.HttpResponse;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpGet;import org.apache.http.impl.client.HttpClients;import org.apache.http.util.EntityUtils;import org.dom4j.Document;import org.dom4j.DocumentException;import org.dom4j.DocumentHelper;import org.dom4j.Element;import java.io.IOException;import java.util.regex.Matcher;import java.util.regex.Pattern;/** * 检查单词是否正确,错误给出提示 * * @author ruyi.yury * @date 2018/6/15 0015 10:16 */public class CheckWord {    /**     *     * @param word     * @return     */    public static boolean checkWords(String word) {        boolean isRight = true;        HttpClient client = HttpClients.createDefault();        HttpGet get = new HttpGet("http://fanyi.youdao.com/openapi.do?keyfrom=keyform&key=key&type=data&doctype=xml&version=1.1&q="                + word);//把keyfrom替换为自己的,把key替换为自己的        HttpResponse response = null;        try {            response = client.execute(get);            HttpEntity entity = response.getEntity();            String str = EntityUtils.toString(entity, "utf-8");            Document doc = DocumentHelper.parseText(str);            Element root = doc.getRootElement();            Element query = root.element("query");            Element paragraph = root.element("translation").element("paragraph");            if (!isChinese(paragraph.getText())){                isRight = false;            }        } catch (IOException e) {            e.printStackTrace();        } catch (DocumentException e) {            e.printStackTrace();        }        return isRight;    }    /**     * 读取文本     * @param content     * @return     */    public static String readText(String content) {        String[] text = content.split(" ");        System.out.println(text.length);        System.out.println(text.toString());        for (int i = 0; i text.length; i++) {            if(!checkWords(text[i].substring(0,text[i].length()-1))){                    text[i] = "("+text[i]+")--不正确";            }        }        StringBuilder checkdText = new StringBuilder();        for (int i = 0; i text.length; i++) {            checkdText.append(text[i]+" ");        }        System.out.println(checkdText.toString());        return checkdText.toString();    }    /**     * 判断是否为中文     * @param word     * @return     */    public static boolean isChinese(String word){        String regEx = "[\u4e00-\u9fa5]";        Pattern pattern = Pattern.compile(regEx);        Matcher matcher = pattern.matcher(word);        boolean flag = false;        if(matcher.find()){            flag = true;        }        return flag;    }    public static void main(String[] args) {        readText("this eeee your fatestds!");    }}小程序

TAG标签: 微信小程序确定的英文

http://www.xiaochengxub.com/read-100706.html