Skip to content

Commit

Permalink
add random summarizer
Browse files Browse the repository at this point in the history
  • Loading branch information
kariminf committed Oct 8, 2018
1 parent 1de1fb8 commit 88b5428
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 2 deletions.
105 changes: 105 additions & 0 deletions src/main/java/kariminf/as/confs/multiling/multiling2015/MssROUGE2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* This file is part of AllSummarizer project
*
* Copyright 2015 Abdelkrime Aries <kariminfo0@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package kariminf.as.confs.multiling.multiling2015;

import java.io.File;
import java.io.IOException;

import kariminf.ktoolja.file.FileManager;


public class MssROUGE2 {

private static final String peerFolder =
"/home/kariminf/Data/ATS/Mss15Test/tests/baselines/random/";

private static final String summaryFolder =
"/home/kariminf/Data/ATS/Mss15Test/model";

private static final String [] langs =
{
"af", "ar", "bg", "ca", "cs", "de", "el", "en", "eo",
"es", "eu", "fa", "fi", "fr", "he", "hr", "hu", "id",
"it",
"ja", "ms", "nl", "no", "pt", "ro", "ru", "sh",
"sl", "sr", "sv", "th", "tr", "vi", "zh",
"ka", "ko", "pl", "sk"
};

/**
* @param args
*/
public static void main(String[] args) {

for (String lang: langs){//langs

File folder = new File(summaryFolder + "/" + lang + "");
if (! folder.exists()) continue;
if (! folder.isDirectory()) continue;


String xmlcontent = "<ROUGE-EVAL version=\"1.0\">\n";

File[] files = folder.listFiles();
for (File file: files){

String fileName = file.getName();
if (! fileName.endsWith(".txt")) continue;

fileName = fileName.substring(0, fileName.length()-4);//4//12
//String newfolderName = outFolder + lang + "/";
//newfolderName += fileName.substring(0, fileName.length()-9) + "/";

//int pid = 0;
xmlcontent += "<EVAL ID=\""+fileName+"\">\n";

xmlcontent += "<PEER-ROOT>\n";
xmlcontent += peerFolder + lang + "\n";
xmlcontent += "</PEER-ROOT>\n";
xmlcontent += "<MODEL-ROOT>\n";
xmlcontent += summaryFolder + "/" + lang + "\n";
xmlcontent += "</MODEL-ROOT>\n";
xmlcontent += "<INPUT-FORMAT TYPE=\"SPL\">\n";
xmlcontent += "</INPUT-FORMAT>\n";
xmlcontent += "<PEERS>\n";
xmlcontent += "<P ID=\"Random\">" + fileName + ".txt</P>\n";
xmlcontent += "</PEERS>\n";
xmlcontent += "<MODELS>\n";
xmlcontent += "<M ID=\"M"+fileName+"\">" + fileName + ".txt</M>\n";
xmlcontent += "</MODELS>\n";
xmlcontent += "</EVAL>\n";

} //files
xmlcontent += "</ROUGE-EVAL>";

try {

FileManager.saveFile(peerFolder + "/" + lang + "-random2018.xml", xmlcontent);

} catch (IOException e) {
e.printStackTrace();
}

}//languages


}


}
29 changes: 29 additions & 0 deletions src/main/java/kariminf/as/process/baseline/Random.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package kariminf.as.process.baseline;

import java.util.ArrayList;
import java.util.HashMap;

import kariminf.as.process.ScoreHandler;
import kariminf.as.tools.Data;

public class Random implements ScoreHandler {

private HashMap<Integer, Double> scores = new HashMap<>();

@Override
public void setData(Data data) {
int size = data.getSentAmount();
ArrayList<Double> values = new ArrayList<>();
for(int i=0; i<size; i++) values.add((double) i);
for(int i=0; i<size; i++) {
int idx = (int) (Math.random() * values.size());
scores.put(i, values.get(idx));
}
}

@Override
public Double scoreUnit(int unitID) throws UnitNotIncluded {
return scores.get(unitID);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import kariminf.as.preProcess.StaticPreProcessor;
import kariminf.as.process.Scorer;
import kariminf.as.process.baseline.Firsts;
import kariminf.as.process.baseline.Random;
import kariminf.as.process.ssfgc.GC0ScoreHandler;
import kariminf.as.process.ssfgc.GC1ScoreHandler;
import kariminf.as.process.ssfgc.GC2ScoreHandler;
Expand All @@ -37,7 +38,7 @@ public class BaselinesMss2018 {
"/home/kariminf/Data/ATS/Mss15Test/src/";

private static final String outFolder =
"/home/kariminf/Data/ATS/Mss15Test/tests/baselines/firsts/";
"/home/kariminf/Data/ATS/Mss15Test/tests/baselines/random/";

private static final String [] langs =
{ "af",
Expand Down Expand Up @@ -116,7 +117,7 @@ public int sentNum (){

public void summarize(){

Firsts ssh = new Firsts();
Random ssh = new Random();

ssh.setData(data);
scorer = Scorer.create(ssh);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public static void main(String[] args) {
preprocessor.setData(data);
preprocessor.preProcess(text);

System.out.println(data.getSentWords());

System.exit(0);


/*for(int i = 0; i < 10; i++){
for(int j = i+1; j < 10; j++){
Expand Down

0 comments on commit 88b5428

Please sign in to comment.