0

印刷できる110個のドキュメントの類似性マトリックスを印刷する必要があり、出力は類似性が最も高いドキュメントペアです。

次に、これらのドキュメント ペアに基づいてクラスターを形成する必要があります。

(4,29),(29,76),(45,89)問題は、出力が必要なため、これらのドキュメントのペアを保存できないこと(4,29,76),(45,89)ですが、 maxarray メソッドが呼び出され、出力が input と同じになるたびに配列リストが上書きされるため、取得できません。

    public class SimilarityMatrix {


               public static void main(String[] args) throws IOException  {

                         int array[][]=new int[120][120];

      outputArray(array);
      }

     public static void outputArray(int[][] array) throws IOException {
                                            FileOutputStream out=new FileOutputStream("similaritymatrix.txt");
                    PrintStream p=new PrintStream(out); 

     int rowSize = array.length;
     int columnSize = array[0].length;
     for(int i = 1; i <= 110; i++) {
     System.out.print("[");
     p.print("[");

     for(int j = 1; j <= 109; j++) {
         if(i!=j && i<j)
         {
             app obj=new app();


             array[i][j]=         obj.main(i,j);


         }

         else if(i>j || i==j)
         {
                  array[i][j]=0;
         }        
                            System.out.print(" " + array[i][j]);
                            p.print(" " + array[i][j]);






     }
     System.out.println(" ]");
      p.println(" ]");

     }
     System.out.println();
      p.println();
      max(array);
     }
      public static void max(int array[][]) throws FileNotFoundException
      {
                                                  FileOutputStream out=new FileOutputStream("similaritymatrix1.txt");
                    PrintStream p=new PrintStream(out); 

     int maxValue = 1;

      int i=1;

      int j=1;
     for (  i = 1; i <= 110; i++) {
            for ( j = 1; j <= 109; j++)
            {

            if (array[i][j] > maxValue) {
            maxValue = array[i][j];

            }
            }}

             for ( i = 1; i <= 110; i++) {
            for ( j = 1; j <= 109; j++)
            {
            if(maxValue==array[i][j]){
                                  System.out.println("\nMax values in 2D array at d"+i+"d"+j+"max value ="+maxValue);


                                  p.println("\nMax values in 2D array at d"+i+"d"+j+"max value ="+maxValue);

    array[i][j]=0;
 ArrayList a = new ArrayList();
             a.add(i);
            a.add(j);
             if(!a.contains(i)&& !a.contains(j))
             {
                 a.add(i);
                 a.add(j);
                                   System.out.println("the cluster is" +a);

             }
                else  if(a.contains(i)&& !a.contains(j))
                  {
                      a.add(j);
                                        System.out.println("the cluster is" +a);

                  }
                else  if(!a.contains(i)&& a.contains(j))

                  {
                      a.add(i);
                                        System.out.println("the cluster is" +a);

                  }


                }}}


     for(  i=1;i<=110;i++)
              {
                  p.print("[");
              System.out.print("[");

                  for( j=1;j<=109;j++)
                  {
                      System.out.print(" "+ array[i][j]);
                      p.print(" "+ array[i][j]);

                  }

                p.println(" ]");
                System.out.println("]");


              }
        if(maxValue>1)         
      max(array);


      }
    }

     class app {



        private static ArrayList<String> load(String f1) throws FileNotFoundException{

            Scanner reader = new Scanner(new File(f1));

            ArrayList<String> out = new ArrayList<String>();

            while (reader.hasNext()){

                String temp = reader.nextLine();

                String[] sts = temp.split(" ");

                for (int i = 0;i<sts.length;i++){

                    if(sts[i] != "" && sts[i] != " " && sts[i] != "\n")

                        out.add(sts[i]);

                }

            }

            return out;

        }



        private static void write(ArrayList<String> out, String fname) throws IOException{


            FileWriter writer = new FileWriter(new File(fname));

            for (int i = 0;i<out.size();i++){

                writer.write(out.get(i) + "\t");

            }

            writer.close();

        }



        public static int main(int a,int b) throws IOException {

    int count=0;

            ArrayList<String> file1;

            ArrayList<String> file2;

            ArrayList<String> out = new ArrayList<String>();

            file1 = load(a+".txt");

            file2 = load(b+".txt");

            for(int i = 0;i<file1.size();i++){

        String word1 = file1.get(i);

        for (int z = 0; z <file2.size(); z++){

            if (word1.equalsIgnoreCase(file2.get(z))){


                        boolean already = false;

                        for (int q = 0;q<out.size();q++){

                            if (out.get(q).equalsIgnoreCase(file1.get(i))){

                                already = true;


                            }

                        }


                        if (already==false){

                            out.add(file1.get(i));

    count++;
                        }}}}


                    return count;








        }


        }

これは私がこれまでに試したコードで、出力を取得していますが、入力と同じです

4

0 に答える 0