在字符串中搜索停用词 [英] Searching a String for stop words

查看:109
本文介绍了在字符串中搜索停用词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试搜索我的字符串zach中的停止词,BE,TO,OF,和,A,IN,那个,我,IT,ON,IN,BUT,IS,WITH。

I am trying to search my string "zach" for the stop words THE", "BE", "TO", "OF", "AND", "A", "IN", "THAT", "I", "IT", "ON", "IN", "BUT", "IS", "WITH".

我不确定字符串搜索方法会有效或有更好的方法。

I am not sure if the string search method will work or if there is a better way to do this.

package zk;

public class Class 
{

    public boolean isNonStopWord(int[] nums, int value)
    {

    }
    public String search( String [] Strings , String july) {
        String [] skoal = {"THE", "BE", "TO", "OF", "AND", "A", "IN",
                "THAT", "I", "IT", "ON", "IN", "BUT", "IS", "WITH"};
        for ( String i = 0, ) {
            return false;
        }
        return true;
    }

    public static void main(String [] args) {

        String zach = ("Amazon offered up more answers Thursday about what"
                + " caused a bunch of websites to fail two days ago. According "
                + "to a postmortem by the company's cloud services business, "
                + "around 9:37 a.m. PT Tuesday an Amazon worker incorrectly"
                + " punched in a command while trying to debug an issue. "
                + "That command shut down a large set of servers at Amazon Web "
                + "Services' Northern Virginia site, causing a domino effect of"
                + " problems. Other services that relied on those S3 cloud"
                + " storage servers were disrupted. Also, removing so much "
                + "server capacity required a full system restart, which then "
                + "took longer than expected, AWS said. The sites affected "
                + "included Quora, Imgur, IFTTT, Giphy and Slack. Amazon was "
                + "able to fix the issue by about 2 p.m. PT.");
        zach = zach.replace(",","");
        zach = zach.replace(".","");
        zach = zach.toUpperCase();
        String [] strings = zach.split(" ");
        for (String s1: strings) 
        {
                System.out.println(s1);

        }
    }
}


推荐答案

使用 String#matches() here:

public boolean hasWord(String input, String word) {
    return input.matches(".*\\b" + word + "\\b.*"));
}

// now call the above method from somewhere
public static void main (String[] args) {
    String [] skoal = {"THE", "BE", "TO", "OF", "AND", "A", "IN",
                       "THAT", "I", "IT", "ON", "IN", "BUT", "IS", "WITH"};
    String zach = "...";           // your original content
    zach = zach.replace(",", "");  // remove punctuation
    zach = zach.replace(".", "");
    zach = zach.toUpperCase();     // uppercase

    for (String stop : skoal) {
        if (hasWord(stop)) {
            System.out.println(word + " true");
        }
        else {
            System.out.println(word + " false");
        }
    }
}

这篇关于在字符串中搜索停用词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆