/*******************************************************************************
* Copyright 2016
* Ubiquitous Knowledge Processing (UKP) Lab
* Technische Universität Darmstadt
*
* 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 de.tudarmstadt.ukp.lmf.transform.sensealignments;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.sql.SQLException;
import java.util.List;
import java.util.Set;
import de.tudarmstadt.ukp.lmf.model.core.Sense;
import de.tudarmstadt.ukp.lmf.transform.DBConfig;
import de.tudarmstadt.ukp.lmf.transform.alignments.SenseAlignment;
import de.tudarmstadt.ukp.lmf.transform.alignments.SenseAlignmentUtils;
import de.tudarmstadt.ukp.lmf.transform.omegawiki.OmegaWikiLMFMap;
import de.tudarmstadt.ukp.omegawiki.api.DefinedMeaning;
import de.tudarmstadt.ukp.omegawiki.api.OmegaWiki;
import de.tudarmstadt.ukp.omegawiki.api.SynTrans;
public class OmegaWikiWiktionaryAlignment
extends SenseAlignment
{
public StringBuilder logString;
private final SenseAlignmentUtils saUtils;
private final OmegaWiki ow;
private final int owLanguage;
private final String owLangId;
public OmegaWikiWiktionaryAlignment(String sourceUrl, String destUrl,String dbDriver,
String dbVendor, String alignmentFile, String user, String pass,
OmegaWiki ow,int language) throws SQLException, InstantiationException,
IllegalAccessException, ClassNotFoundException, FileNotFoundException
{
super(sourceUrl, destUrl,dbDriver,dbVendor, alignmentFile, user, pass,UBY_HOME);
this.ow = ow;
this.owLanguage = language;
this.owLangId = OmegaWikiLMFMap.mapLanguage(owLanguage);
Class.forName(dbDriver);
DBConfig s = new DBConfig(sourceUrl,dbDriver,dbVendor, user, pass, true);
DBConfig d = new DBConfig(destUrl,dbDriver,dbVendor,user, pass, true);
saUtils = new SenseAlignmentUtils(s, d, 1, 0, "temp_MiM", "temp_MiM");
saUtils.createDefaultTempTables(false);
//saUtils=null;
logString = new StringBuilder();
}
@Override
public void getAlignment()
{
System.out.println("Starting getting alignment for OmegaWiki - Wiktionary "
+ getAlignmentFileLocation());
BufferedReader input = null;
try {
input = new BufferedReader(new FileReader(getAlignmentFileLocation()));
String line = null;
int count = 1;
while((line =input.readLine()) != null){
String owId = line.split(",")[1].replaceAll("\"","");
String wktId = line.split(",")[0].replaceAll("\"","");
System.out.println("OW ID " +owId +" WKT ID " +wktId);
DefinedMeaning dm = ow.getDefinedMeaningById(Integer.parseInt(owId)); //Synset!!!
Set<SynTrans> sts = dm.getSynTranses(owLanguage); //Senses!!!
System.out.println(saUtils);
List<Sense> senseWKN = saUtils.getSensesByExternalRefID(wktId, 1,false);
System.out.println(senseWKN.size());
for (SynTrans st : sts)
{
List<Sense> first = ubySource.getSensesByOriginalReference("OmegaWiki_"+owLangId+"_synTrans", ""+st.getSyntransid());
Sense sourceSense = first.get(0);
for (Sense targetSense: senseWKN)
{
addSourceSense(sourceSense);
addDestSense(targetSense);
System.out.println(count++);
}
}
}
input.close();
//Retrieve alignments
saUtils.destroyTempTable();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}