2017-03-17 6 views
-2

本当にシンプルなものが見つからないように感じますが、見つけられません。 このコードの目的は、Shakespeareファイルを取得し、ハッシュマップを使用して、テキストによって単語が与えられた回数と「n」文字の単語を検索することです。しかし、私はエラーが発生するので、私はエラーを取得するためにデバッグの部分に行くことができませんエラーを修正する方法:シンボルを見つけることができません

Bard.java:13: error: cannot find symbol 
    Pattern getout = Pattern.compile("[\\w']+"); //this will take only the words 
    ^ symbol: class Pattern location: class Bard 
Bard.java:13: error: cannot find symbol 
    Pattern getout = Pattern.compile("[\\w']+"); //this will take only the words 

プラスいくつかの場所に加えて。ヘルプは非常に高く評価されます。

import java.io.*; 
import java.util.*; 

public class Bard { 

    public static void main(String[] args) { 

    HashMap < String, Integer > m1 = new HashMap < String, Integer >(); // sets the hashmap 

    //create file reader for the shakespere text 
    try (BufferedReader br = new BufferedReader(new FileReader("shakespeare.txt"))) { 
     String line = br.readLine(); 
     Pattern getout = Pattern.compile("[\\w']+"); //this will take only the words 

     //create the hashmap 
     while (line != null) { 
     Matcher m = getout.matcher(line); //find the relevent information 

     while (m.find()) { 
      if (m1.get(m.group()) == null && !m.group().toUpperCase().equals(m.group())) { //find new word that is not in all caps. 
      m1.put(m.gourp(), 1); 
      } else { //increments the onld word 
      int newValue = m1.get(m.group()); 
      newValue++; 
      m1.put(m.group, newValue); 
      } 
     } 
     line = br.readLine(); 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 


    try (BufferedReader br2 = new BufferedReader(new FileReader("input.txt"))) { 
     String line2 = br2.readLine(); 
     FileWriter output = new FileWriter("analysis.txt"); 

     while (line2 != null) { 

     if (line2.matches("[\\d\\s]+")) { // if i am dealing with the two integers 
      String[] args = line.split(" "); // split them up 
      wordSize = Integer.parseInt(args[0]); // set the first on the the word size 
      numberOfWords = Integer.parseInt(args[1]); // set the other one to the number of words wanted 
      String[] wordsToReturn = new String[numberOfWords]; //create array to place the words 
      int i = 0; 
      int j; 
      for (String word: m1.keySet()) { // 
      if (word.length() == wordSize) { 
       wordToReturn[i] = word; 
       i++; 
      } 


      for (j = 0; numberOfWords > j; j++) { 
       output.write(wordToReturn[j]); 
      } 
      } 
     } else { 
      output.write(m1.get(line2)); 
     } 


     } 
     line2 = br2.readLine(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    } 
} 
+2

の可能性のある重複(http://stackoverflow.com/questions/25706216/what-does-a-cannot-find [「シンボルが見つかりません」コンパイルエラーがどういう意味?] -symbol-compilation-error-mean) –

答えて

3

Patternクラスをインポートしていません。それをインポートします -

import java.util.regex.*; 
関連する問題