<commit_before>package fr.eurecom.eventspotter;

import java.io.BufferedWriter;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.apache.commons.io.FileUtils;
import fr.eurecom.eventspotter.caslight.FeatureStructure;
import fr.eurecom.eventspotter.worker.EventSpotterLight;


public class EventSpotter
{
    private String titlesFilePath;
    private int maxTitleLength;
    // private Set<String> SUPPORTED_MIMETYPES = Collections.unmodifiableSet(new HashSet<String>(
    //     Arrays.asList("document/plain")));
    // public static final Integer defaultOrder = ServiceProperties.ORDERING_PRE_PROCESSING;
    private EventSpotterLight eventspotter;
    //  final Logger logger = (Logger) LoggerFactory.getLogger(this.getClass());
    private String dbPath;
    private String dbDriver;
    private String dbUser;
    private String dbPassword;
   


    public String start_spotter(String document) throws IOException
    {
        this.titlesFilePath = "/opt/event-titles.list";
        this.dbPath = "jdbc:mysql://localhost/trial";
        this.dbDriver = "com.mysql.jdbc.Driver";
        this.dbUser = "root";
        this.dbPassword = "<PASSWORD>";
        this.maxTitleLength = 1000;
        this.eventspotter = new EventSpotterLight(titlesFilePath, dbDriver, dbPath, dbUser, dbPassword, maxTitleLength);
        //logger.info("EventSpotter initiated with titles file:" + titlesFilePath);

        //logger.info("Running eventSpotter...");
        Set<FeatureStructure> spottedevents = eventspotter.spotevents(document);
        //logger.info("Processing spotted events(" + spottedevents.size() + ")");
        File file = new File("output.txt");
        try{
            // if file doesnt exist, then create it
        	if (file.exists()) {
        		file.delete();
            }
        	file.createNewFile();

        } catch (IOException e) {
            e.printStackTrace();
        }
        Set<FeatureStructure> s = new HashSet<FeatureStructure>(spottedevents);
        for(FeatureStructure str : s)
        {
        	for(FeatureStructure ss : s)
        	{
        	if(!str.getFeature("title from input").getValueAsString().contentEquals(ss.getFeature("title from input").getValueAsString()))
        	{
        			if(str.getFeature("title from input").getValueAsString().contains(ss.getFeature("title from input").getValueAsString()))
        		        		{
        				if(ss.getFeature("title from input").getValueAsString()!="null")
        			ss.getFeature("title from input").setValue("null");
        		}
        		}
        	}
        }
        
        Iterator<FeatureStructure> iter = s.iterator();
        while (iter.hasNext()) {
            if (iter.next().getFeature("title from input").getValueAsString() == "null") iter.remove();
        }
        for (FeatureStructure fs : s) 
        {      	
            
        	String label= fs.getFeature("title from input").getValueAsString();
            String new_label="<EVENT>"+label+"</EVENT>";
            if(!document.contains(new_label))
            	{
            	document=document.replaceAll("([!\\s?.])"+label+"([!\\s?.])","$1"+new_label+"$2");
            	
            	document=document.replaceAll("([!\\s?.])"+label+"([!\\s?.])","$1"+new_label+"$2");
            	}<commit_msg>updated db name as eventspotterdb<commit_after>package fr.eurecom.eventspotter;

import java.io.BufferedWriter;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.apache.commons.io.FileUtils;
import fr.eurecom.eventspotter.caslight.FeatureStructure;
import fr.eurecom.eventspotter.worker.EventSpotterLight;


public class EventSpotter
{
    private String titlesFilePath;
    private int maxTitleLength;
    // private Set<String> SUPPORTED_MIMETYPES = Collections.unmodifiableSet(new HashSet<String>(
    //     Arrays.asList("document/plain")));
    // public static final Integer defaultOrder = ServiceProperties.ORDERING_PRE_PROCESSING;
    private EventSpotterLight eventspotter;
    //  final Logger logger = (Logger) LoggerFactory.getLogger(this.getClass());
    private String dbPath;
    private String dbDriver;
    private String dbUser;
    private String dbPassword;
   


    public String start_spotter(String document) throws IOException
    {
        this.titlesFilePath = "/opt/event-titles.list";
        this.dbPath = "jdbc:mysql://localhost/eventspotterdb";
        this.dbDriver = "com.mysql.jdbc.Driver";
        this.dbUser = "root";
        this.dbPassword = "<PASSWORD>";
        this.maxTitleLength = 1000;
        this.eventspotter = new EventSpotterLight(titlesFilePath, dbDriver, dbPath, dbUser, dbPassword, maxTitleLength);
        //logger.info("EventSpotter initiated with titles file:" + titlesFilePath);

        //logger.info("Running eventSpotter...");
        Set<FeatureStructure> spottedevents = eventspotter.spotevents(document);
        //logger.info("Processing spotted events(" + spottedevents.size() + ")");
        File file = new File("output.txt");
        try{
            // if file doesnt exist, then create it
        	if (file.exists()) {
        		file.delete();
            }
        	file.createNewFile();

        } catch (IOException e) {
            e.printStackTrace();
        }
        Set<FeatureStructure> s = new HashSet<FeatureStructure>(spottedevents);
        for(FeatureStructure str : s)
        {
        	for(FeatureStructure ss : s)
        	{
        	if(!str.getFeature("title from input").getValueAsString().contentEquals(ss.getFeature("title from input").getValueAsString()))
        	{
        			if(str.getFeature("title from input").getValueAsString().contains(ss.getFeature("title from input").getValueAsString()))
        		        		{
        				if(ss.getFeature("title from input").getValueAsString()!="null")
        			ss.getFeature("title from input").setValue("null");
        		}
        		}
        	}
        }
        
        Iterator<FeatureStructure> iter = s.iterator();
        while (iter.hasNext()) {
            if (iter.next().getFeature("title from input").getValueAsString() == "null") iter.remove();
        }
        for (FeatureStructure fs : s) 
        {      	
            
        	String label= fs.getFeature("title from input").getValueAsString();
            String new_label="<EVENT>"+label+"</EVENT>";
            if(!document.contains(new_label))
            	{
            	document=document.replaceFirst("([!\\s?.])"+label+"([!\\s?.])","$1"+new_label+"$2");
         }
{'fraction_non_alphanumeric': 0.13167739039353585, 'fraction_numerical': 0.0020948675744426157, 'mean_word_length': 2.6806167400881056, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4814685', 'n_tokens_mistral': 1920, 'n_tokens_neox': 1873, 'n_words': 353}