2017-03-27 20 views
0

ストップワード "zach"でストップワード "THE"、 "BE"、 "TO"、 "OF"、 "AND"、 "A"、 "IN"を検索しようとしています。 "THAT"、 "I"、 "ON"、 "IN"、 "BUT"、 "IS"、 "WITH"のいずれかであるかどうかはわかりません。これを行うには良い方法であるストップワードの文字列検索

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); 

     } 
    } 
} 
+0

「ストップワード」で何をしたいですか? –

+0

@ElliottFrisch私はそれらの隣でfalseを返し、他のすべての隣で真を返したい。 – zach

答えて

0

ここString#matches()を使用してに何か問題があるでしょう:あなたが使用していると仮定すると、

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"); 
     } 
    } 
} 
+0

私は、単語を見つけて真偽を返すためにnonStopWordメソッドが必要です。そして、私はメインのメソッドを呼び出す必要があります。 – zach

+0

'isNonStopWord()'のシグネチャを理解できません。整数はあなたのテキストを検索するために何をしなければなりませんか? –

+0

シグネチャが間違っていますか?ブール値を正しく書き込む方法がわかりません – zach

1

Javaの8+は、あなたが

String[] strings = zach.split("\\s+"); 
for (String s1 : strings) { 
    System.out.println(s1 + ": " 
      + Stream.of(skoal).noneMatch(s -> s.equals(s1))); 
} 

ようStream.noneMatchを使用する場合がありますそして、\\s+は、1つ(またはそれ以上)正規表現で空白にマッチします。