package tbx2rdf.types;

import tbx2rdf.vocab.ONTOLEX;
import tbx2rdf.vocab.TBX;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.vocabulary.RDF;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import tbx2rdf.Main;
import tbx2rdf.Mappings;
import tbx2rdf.datasets.lexvo.LexvoManager;
import tbx2rdf.types.abs.impIDLang;
import tbx2rdf.vocab.SKOS;

/**
 * This class represents a Lexical Entry
 *
 * @author Philipp Cimiano - Universität Bielefeld
 * @author Victor Rodriguez - Universidad Politécnica de Madrid
 */
public class LexicalEntry extends Describable {

    static LexicalEntry createFromSPARQL(String uri, Model model) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }


    final public List<TermCompList> Decomposition = new ArrayList<TermCompList>();


    final public List<TermNoteGrp> TermNotes = new ArrayList<TermNoteGrp>();

    public String Lemma;

    public LexicalEntry(String language, Mappings mappings) {
        super(language, mappings);
    }

    public LexicalEntry(String lemma, String language, Mappings mappings) {
        super(language, mappings);
        Lemma = lemma;

    }


    @Override
    public void toRDF(Model model, Resource parent) {
        String newuri=/*Main.DATA_NAMESPACE+*/"LexicalEntry-"+URLEncoder.encode(Lemma);
        this.setID(newuri);

        final Resource term = getRes(model);
        super.toRDF(model, term);
    
        term.addProperty(RDF.type, ONTOLEX.LexicalEntry);

//        term.addProperty(ONTOLEX.language, lang);
        Resource rlan=LexvoManager.mgr.getLexvoFromISO2(lang);
        term.addProperty(ONTOLEX.language, rlan);    //before it was the mere constant "language"
        
        final Resource sense = getSubRes(model, "Sense");

        sense.addProperty(ONTOLEX.reference, parent);
        
        term.addProperty(ONTOLEX.sense, sense);

        final Resource canonicalForm = getSubRes(model, "CanonicalForm");

        term.addProperty(ONTOLEX.canonicalForm, canonicalForm);

        canonicalForm.addProperty(ONTOLEX.writtenRep, Lemma, lang);
        
                
        for(TermCompList decomposition : Decomposition) {
            decomposition.toRDF(model, term);
        }
        for(TermNoteGrp note : TermNotes) {
            note.toRDF(model, term);
        }
    }
}

@@ -51,34 +51,8 @@
 EX;%0A
-import tbx2rdf.vocab.TBX;%0A
 impo
@@ -124,254 +124,128 @@
 del.
-ModelFactory;%0Aimport com.hp.hpl.jena.rdf.model.Resource;%0Aimport com.hp.hpl.jena.rdf.model.Statement;%0Aimport com.hp.hpl.jena.vocabulary.RDF;%0Aimport java.net.URLEncoder;%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.HashSet
+Resource;%0Aimport com.hp.hpl.jena.vocabulary.RDF;%0Aimport java.io.UnsupportedEncodingException;%0Aimport java.net.URLEncoder
 ;%0Aim
@@ -259,16 +259,21 @@
 va.util.
+Array
 List;%0Aim
@@ -291,32 +291,12 @@
 til.
-Set;%0Aimport tbx2rdf.Main
+List
 ;%0Aim
@@ -365,71 +365,8 @@
 ger;
-%0Aimport tbx2rdf.types.abs.impIDLang;%0Aimport tbx2rdf.vocab.SKOS;
 %0A%0A/*
@@ -1226,21 +1226,17 @@
 %0A    %7D%0A%0A
-%0A    
+%09
 @Overrid
@@ -1240,179 +1240,324 @@
 ride
-%0A    
+ %0A%09
 public 
-void toRDF(Model model, Resource parent) %7B%0A        String newuri=/*Main.DATA_NAMESPACE+*/%22LexicalEntry-%22+URLEncoder.encode(Lemma);%0A        this.setID(newuri);%0A
+String getID() %7B%0A%09%09if(id != null) %7B%0A%09%09%09return id;%0A%09%09%7D else %7B%0A%09%09%09try %7B%0A%09%09%09%09return String.format(%22%25s-%25s%22, URLEncoder.encode(Lemma, %22UTF-8%22), lang);%0A%09%09%09%7D catch(UnsupportedEncodingException x) %7B%0A%09%09%09%09throw new RuntimeException(x);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A    @Override%0A    public void toRDF(Model model, Resource parent) %7B
 %0A   

Fix URL encoding issues