title: How to print tagged values from a file?
body: <p>I had to write a code to identify the language of tweets and to print out the tweets of a certain language. I have written the language identification part, but cannot get to print only the lines necessary. </p>
  
  <p>Here is the code: </p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  import weka.classifiers.bayes.NaiveBayes;
  import weka.classifiers.functions.SMO;
  import weka.classifiers.trees.RandomForest;
  import weka.core.Instance;
  import weka.core.Instances;
  import weka.core.converters.ConverterUtils.DataSource;
  
  public class Lang_Detect 
  {
      public static weka.classifiers.Classifier c;
      public static HashMap&lt;String,String&gt; trigram=new HashMap&lt;String,String&gt;();
  
      public static void initiate() throws Exception
      {
          c = loadModel("C:\\Users\\DIV\\ff\\Maithili\\nb.model"); // loads nb model
      }
      public static NaiveBayes loadModel(String path) throws Exception 
      {
          NaiveBayes classifier;
          FileInputStream fis = new FileInputStream(path);
          ObjectInputStream ois = new ObjectInputStream(fis);
  
          classifier = (NaiveBayes) ois.readObject();
          ois.close();
          return classifier;
      }
      public static void read_trigram()
      {
          try
          {
              FileInputStream fis = new FileInputStream("C:\\Users\\DIV\\ff\\Maithili\\Trigram.txt");
              BufferedReader br = new BufferedReader(new InputStreamReader(fis,"UTF-8"));
              String line;
              while((line = br.readLine())!=null)
              {
                  String words[]=line.split(":");
                  trigram.put(words[0].trim(), "");
              }
              fis.close();
          }catch(IOException f){}    
      }
      public static String feature_vector(String line)
      {
          String vector="";
  
          String words[]=line.split(" ");
          HashMap&lt;String,String&gt; local_word=new HashMap&lt;String,String&gt;();
  
          for(int i=0;i&lt;words.length;i++)
          {
              char ch[]=words[i].toCharArray();
              for(int j=0;j&lt;ch.length-2;j++)
              {
                  local_word.put(ch[j]+""+ch[j+1]+""+ch[j+2], "");    
              }
          }
  
          for (Map.Entry&lt;String, String&gt; entry : trigram.entrySet()) 
          {
              if(local_word.containsKey(entry.getKey()))
              {
                  vector+="1,";
              }
              else
              {
                  vector+="0,";
              }
          }
  
          return vector;
      }
      public static String lang_tag(String file) throws Exception
      {
  
          String tagged_sentence="";
          int l=0,cntr=0;;
          //String words[]=sentence.toLowerCase().split(" ");
          StringBuffer str=new StringBuffer();
  
          read_trigram();
  
          // TODO Auto-generated method stub
          int count=1;
          str.append("@relation Language\n");
          for (Map.Entry&lt;String, String&gt; entry : trigram.entrySet()) 
          {
              str.append("@attribute Trigram"+count+" numeric\n");
              count++;
          }
          str.append("@attribute class {HN,NP,MT}\n");
          str.append("@DATA\n");
  
          try
          {
              FileInputStream fis = new FileInputStream(file);
              BufferedReader br = new BufferedReader(new InputStreamReader(fis,"UTF-8"));
              String line;
              while((line = br.readLine())!=null)
              {
                  str.append(feature_vector(line)+"?\n");
              }
              fis.close();
          }catch(IOException f){}   
  
          Global.file_update("C:\\Users\\DIV\\ff\\Maithili\\HN_NP_MT_Unlabelled.arff", str.toString());
  
          Instances unlabeled = new Instances(
                  new BufferedReader(
                    new FileReader("HN_NP_MT_Unlabelled.arff")));
  
          // set class attribute
          unlabeled.setClassIndex(unlabeled.numAttributes() - 1);
  
          Instances labeled = new Instances(unlabeled);
  
          // label instances
          for (int i = 0; i &lt; unlabeled.numInstances(); i++) 
          {
            double clsLabel = c.classifyInstance(unlabeled.instance(i));
            String tag="";
  
            if(clsLabel==0.0)
                tag="HN";
            else if(clsLabel==1.0)
                tag="NP";
            else if(clsLabel==2.0)
            {
                tag="MT";
                Global.file_append("C:\\Users\\DIV\\ff\\Maithili\\Detected_Maithili_Tweets.txt", tag);
            }
  
            System.out.println(tag);
  
          }
          return tagged_sentence.trim();
      }
  
      public static void main(String[] args) throws Exception 
      {
          initiate();
          lang_tag("C:\\Users\\DIV\\ff\\Maithili\\tweets.txt");
  
      }
  
  }
  </code></pre>
  
  <p>As you can see in the lang_tag(), I want to print the lines which are tagged as MT, But I cannot get the lines in any particular variable.
  Can someone help me?</p>