Package dmt.tools

Examples of dmt.tools.CSVFileWriter


        }

        line = reader.readLine();
      }

      CSVFileWriter out = new CSVFileWriter("output/" + clustersCount
          + "clusterCentersMarina.csv", ',');
      out.writeFields(headers);
      for (int i = 0; i < clustersCount; i++)
      {
        Vector<String> fields = clusterCenters.get(i);
        fields.add(0, "Cluster" + i);
        out.writeFields(fields);
      }
      out.close();

    }
  }
View Full Code Here


        .hierarchicalCluster(TextInstance.textInstancesSet);
    int k = 30;
    Set<Set<TextInstance>> clResponsePartition = completeLinkDendrogram
        .partitionK(k);
    Object[] clusters = clResponsePartition.toArray();
    CSVFileWriter out = new CSVFileWriter("completeLinkClustersCSV.csv",
        ',');
    Vector<String> header = new Vector<String>();
    header.add("Cluster label");
    out.writeFields(header);
    Object[] textInstancesArray = TextInstance.textInstancesSet.toArray();
    for (int i = 0; i < textInstancesArray.length; i++)
    {
      for (int j = 0; j < clusters.length; j++)
      {
        if (((Set<TextInstance>) clusters[j])
            .contains(textInstancesArray[i]))
        {
          Vector<String> clusterLabel = new Vector<String>();
          clusterLabel.add((j + 1) + "");
          out.writeFields(clusterLabel);
        }
      }
    }
    out.close();

    HierarchicalClusterer<TextInstance> slClusterer = new SingleLinkClusterer<TextInstance>(
        TextInstance.EUCLIDEAN_DISTANCE);
    Dendrogram<TextInstance> singleLinkDendrogram = slClusterer
        .hierarchicalCluster(TextInstance.textInstancesSet);
    Set<Set<TextInstance>> slResponsePartition = singleLinkDendrogram
        .partitionK(k);
    clusters = slResponsePartition.toArray();
    out = new CSVFileWriter("singleLinkClustersCSV.csv", ',');
    out.writeFields(header);
    for (int i = 0; i < textInstancesArray.length; i++)
    {
      for (int j = 0; j < clusters.length; j++)
      {
        if (((Set<TextInstance>) clusters[j])
            .contains(textInstancesArray[i]))
        {
          Vector<String> clusterLabel = new Vector<String>();
          clusterLabel.add((j + 1) + "");
          out.writeFields(clusterLabel);
        }
      }
    }
    out.close();

  }
View Full Code Here

    }
    ClusterAnalysis jca = new ClusterAnalysis(5, 100, dataPoints);
    jca.startAnalysis();

    Vector<Vector<DataPoint>> clusters = jca.getClusterOutput();
    CSVFileWriter out = new CSVFileWriter("kMeansClustersCSV.csv",
        ',');
    Vector<String> header = new Vector<String>();
    header.add("Document ID");
    header.add("XPath");
    header.add("Cluster label");
    out.writeFields(header);
    for (int i = 0; i < clusters.size(); i++)
    {
      for (int j = 0; j < clusters.get(i).size(); j++)
      {
        DataPoint point = clusters.get(i).get(j);
        String documentId = point.getId().substring(0, point.getId().indexOf("/"));
        String XPath = point.getId().substring(point.getId().indexOf("/"), point.getId().length());
        Vector<String> fields = new Vector<String>();
        fields.add(documentId);
        fields.add(XPath);
        fields.add(i+"");
        out.writeFields(fields);
      }
    }
    out.close();
  }
View Full Code Here

   
    //run first the preProcessor
    (new CSVPreProcessor(inCSV, tmpFile)).run();
   
    CSVFileReader in = new CSVFileReader(tmpFile, ',');
    CSVFileWriter out = new CSVFileWriter(outCSV, ',');
   
    //adding headers
    out.writeFields(getHeaders());

      Vector<String> fields = in.readFields();
      int k=0;
     
      while(fields!=null)
      {
        //update the hashMap
        hashMap.put(fields.get(0)+fields.get(1), fields.get(2).equalsIgnoreCase("0") ? false : true);
       
        //preserve existing fields
       
        //compute the features
        Vector<Feature> features = Feature.getFeatures();
      for(int i=0; i < features.size(); i++)
      {
        Object[] values = features.get(i).getValues(fields, hashMap);
        for(int j = 0; j < values.length; j++)
        {
          try
          {
            fields.add(values[j].toString());
          }
          catch(NullPointerException exception)
          {
            fields.add("?");
          }
         
        }
      }
      fields.remove(3);
      //fields.set(3, new Integer(fields.get(3).length()).toString());
        out.writeFields(fields);
        fields = in.readFields();
        k++;
        //if(k>1000) break;
       
      }
 
      in.close();
      out.close();
     
      ElementTypeFeature.showElementTypes();
      NumberOfCharsStemmedFeature.printWords();
  }
View Full Code Here

   */
  public static void main(String[] args) throws IOException
  {
    int num_instances = 200;
    int countNonNull=0;
    CSVFileWriter out = new CSVFileWriter("clusteringDistancesCSV.csv", ',');
    Vector<String> headers = new Vector<String>();
    headers.add("Euclidean");
    headers.add("Manhattan");
    out.writeFields(headers);

    CSVFileReader in1 = new CSVFileReader("csv_out.csv", ',');
    // skip the headers
    Vector<String> fields1 = in1.readFields();
    fields1 = in1.readFields();
    int count1 = 0;
    while (fields1 != null)
    {
      String id1 = fields1.get(0) + fields1.get(1);
      Object[] bagOfWordsTfIdf1 = fields1.subList(4, fields1.size())
          .toArray();
      TextInstance instance1 = new TextInstance(bagOfWordsTfIdf1, id1);
      CSVFileReader in2 = new CSVFileReader("csv_out.csv", ',');
      Vector<String> fields2 = in2.readFields();
      fields2 = in2.readFields();
      TextInstance instance2;
      Object[] bagOfWordsTfIdf2;
      int count2=0;
      while (fields2 != null)
      {     
        String id2 = fields2.get(0) + fields2.get(1);
        bagOfWordsTfIdf2 = fields2.subList(4, fields2.size()).toArray();
        instance2 = new TextInstance(bagOfWordsTfIdf2, id2);
        Vector<String> distances = new Vector<String>();
        double d1 = TextInstance.computeEuclideanDistance(
            instance1, instance2);
        distances.add(d1+"");
        distances.add(TextInstance.computeManhattanDistance(instance1, instance2)
            + "");
        out.writeFields(distances);
        fields2 = in2.readFields();
        count2++;
        if(count2==num_instances) break;
      }
      fields1 = in1.readFields();
      count1++;
      if(count1==num_instances) break;
    }
    out.close();
    System.out.println(countNonNull);
   
  }
View Full Code Here

  }
 
  public void run() throws IOException
  {
    CSVFileReader in = new CSVFileReader(inCSV, ',');
    CSVFileWriter out = new CSVFileWriter(outCSV, ',');
   
      Vector<String> fields = in.readFields();
      int k=0;
     
      while(fields!=null)
      {
        //run the prefeatures
        Vector<PreFeature> preFeatures = PreFeature.getFeatures();
      for(int i=0; i < preFeatures.size(); i++)
      {
        preFeatures.get(i).run(fields);
      }
      out.writeFields(fields);
        fields = in.readFields();
        k++;
        //if(k>10) break;
       
      }
      in.close();
      out.close();
  }
View Full Code Here

    }
  }
 
  private void listBagOfWords() throws IOException
  {
    CSVFileWriter out = new CSVFileWriter(outCSV, ',');
    Object[] keys = stemWords.keySet().toArray();
   
    for(int i=0; i< keys.length; i++)
    {
      Vector<String> fields = new Vector<String>();
      fields.add(keys[i].toString());
      fields.add(stemWords.get(keys[i]).toString());
      fields.add(stemWordsTotal.get(keys[i]).toString());
      out.writeFields(fields);
    }
    out.close();
  }
View Full Code Here

        .hierarchicalCluster(TextInstance.textInstancesSet);
    int k = 30;
    Set<Set<TextInstance>> clResponsePartition = completeLinkDendrogram
        .partitionK(k);
    Object[] clusters = clResponsePartition.toArray();
    CSVFileWriter out = new CSVFileWriter("completeLinkClustersCSV.csv",
        ',');
    Vector<String> header = new Vector<String>();
    header.add("Cluster label");
    out.writeFields(header);
    Object[] textInstancesArray = TextInstance.textInstancesSet.toArray();
    for (int i = 0; i < textInstancesArray.length; i++)
    {
      for (int j = 0; j < clusters.length; j++)
      {
        if (((Set<TextInstance>) clusters[j])
            .contains(textInstancesArray[i]))
        {
          Vector<String> clusterLabel = new Vector<String>();
          clusterLabel.add((j + 1) + "");
          out.writeFields(clusterLabel);
        }
      }
    }
    out.close();

    HierarchicalClusterer<TextInstance> slClusterer = new SingleLinkClusterer<TextInstance>(
        TextInstance.EUCLIDEAN_DISTANCE);
    Dendrogram<TextInstance> singleLinkDendrogram = slClusterer
        .hierarchicalCluster(TextInstance.textInstancesSet);
    Set<Set<TextInstance>> slResponsePartition = singleLinkDendrogram
        .partitionK(k);
    clusters = slResponsePartition.toArray();
    out = new CSVFileWriter("singleLinkClustersCSV.csv", ',');
    out.writeFields(header);
    for (int i = 0; i < textInstancesArray.length; i++)
    {
      for (int j = 0; j < clusters.length; j++)
      {
        if (((Set<TextInstance>) clusters[j])
            .contains(textInstancesArray[i]))
        {
          Vector<String> clusterLabel = new Vector<String>();
          clusterLabel.add((j + 1) + "");
          out.writeFields(clusterLabel);
        }
      }
    }
    out.close();

  }
View Full Code Here

      }
   
    clusters2In.close();
   
    CSVFileReader in = new CSVFileReader(inCSV, ',');
    CSVFileWriter out = new CSVFileWriter(outCSV, ',');
   
    //adding headers
      fields = in.readFields();
      fields.add("ClusterVictor");
      fields.add("ClusterMarina");
      String toc = fields.get(2);
      fields.remove(2);
      fields.add(toc);
      out.writeFields(fields);
      fields = in.readFields();
      int k=0;
     
      while(fields!=null)
      {
        if(hashMap1.containsKey(fields.get(0)+fields.get(1)))
        {
          fields.add(hashMap1.get(fields.get(0)+fields.get(1)));
        }
        else
        {
          fields.add(""+no_clusters1);
        }
        if(hashMap2.containsKey(fields.get(0)+fields.get(1)))
        {
          fields.add(hashMap2.get(fields.get(0)+fields.get(1)));
        }
        else
        {
          fields.add(""+no_clusters2);
        }
       
        toc = fields.get(2);
        fields.remove(2);
        fields.add(toc);
       
        out.writeFields(fields);
        fields = in.readFields();
        k++;
       
      }
 
      in.close();
      out.close();
  }
View Full Code Here

   
    //run first the preProcessor
    (new CSVPreProcessor(inCSV, tmpFile)).run();
   
    CSVFileReader in = new CSVFileReader(tmpFile, ',');
    CSVFileWriter out = new CSVFileWriter(outCSV, ',');
   
    //adding headers
    out.writeFields(getHeaders());

      Vector<String> fields = in.readFields();
      int k=0;
     
      while(fields!=null)
      {
        //update the hashMap
        hashMap.put(fields.get(0)+fields.get(1), fields.get(2).equalsIgnoreCase("0") ? false : true);
       
        //preserve existing fields
       
        //compute the features
        Feature bagOfWordsFeature = new MostFrequentWordsFeature();
      Object[] values = bagOfWordsFeature.getValues(fields, hashMap);
      for(int j = 0; j < values.length; j++)
      {
        try
        {
          fields.add(values[j].toString());
        }
        catch(NullPointerException exception)
        {
          fields.add("?");
        }
      }
      fields.remove(3);
      //fields.set(3, new Integer(fields.get(3).length()).toString());
        out.writeFields(fields);
        fields = in.readFields();
        k++;
        //if(k>10) break;
       
      }
 
      in.close();
      out.close();
     
      ElementTypeFeature.showElementTypes();
      NumberOfCharsStemmedFeature.printWords();
  }
View Full Code Here

TOP

Related Classes of dmt.tools.CSVFileWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.