Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
wlfxb - a library for creating and processing of TCF data streams. Copyright (C) Yana Panchenko. This file is part of wlfxb. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 
 package eu.clarin.weblicht.wlfxb.lx.xb;
 
 import java.util.List;

Author(s):
Yana Panchenko
 
 public class RelationsLayerStored extends LexiconLayerStoredAbstract implements RelationsLayer {
 
     public static final String XML_NAME = "word-relations";
     @XmlElement(name = .)
     private List<RelationStoredrels = new ArrayList<RelationStored>();
     private LexiconLayersConnector connector;
 
     protected RelationsLayerStored() {
     }
 
     protected RelationsLayerStored(LexiconLayersConnector connector) {
         this. = connector;
     }
 
     protected void setLayersConnector(LexiconLayersConnector connector) {
         this. = connector;
         for (RelationStored rel : ) {
             connect(rel);
 
         }
     }
 
     @Override
     public boolean isEmpty() {
         return .isEmpty();
     }
 
     @Override
     public int size() {
         return .size();
     }
 
     @Override
     public Relation getRelation(int index) {
         return .get(index);
     }
 
     @Override
     public Relation[] getRelations(Lemma lemma) {
         List<RelationrelList = ..get(lemma);
         if (relList != null) {
             return relList.toArray(new Relation[relList.size()]);
         } else {
             return new Relation[0];
         }
     }
 
     @Override
     public Lemma[] getLemmas(Relation rel) {
         if (rel instanceof RelationStored) {
             RelationStored relStored = (RelationStoredrel;
             List<Lemmalemmas = new ArrayList<Lemma>();
             for (TermStored t : relStored.terms) {
                 if (t.lemId != null) {
                     lemmas.add(..get(t.lemId));
                 }
             }
             return lemmas.toArray(new Lemma[lemmas.size()]);
         } else {
             return null;
        }
    }
    @Override
    public String[] getWords(Relation rel) {
        if (rel instanceof RelationStored) {
            RelationStored relStored = (RelationStoredrel;
            List<Stringwords = new ArrayList<String>();
            for (TermStored t : relStored.terms) {
                if (t.lemId != null) {
                    words.add(..get(t.lemId).getString());
                } else if (t.word != null) {
                    words.add(t.word);
                }
            }
            return words.toArray(new String[words.size()]);
        } else {
            return null;
        }
    }
    @Override
    public Relation addRelation(String typeString functionInteger frequencyList<Termterms) {
        RelationStored rel = new RelationStored();
        rel.type = type;
        rel.function = function;
        rel.freq = frequency;
        for (Term term : terms) {
            if (term instanceof TermStored) {
                rel.terms.add((TermStoredterm);
            }
        }
        connect(rel);
        .add(rel);
        return rel;
    }
    private void connect(RelationStored rel) {
        for (TermStored term : rel.terms) {
            if (term.lemId != null) {
                Lemma lemma = ..get(term.lemId);
                if (!..containsKey(lemma)) {
                    ..put(lemmanew ArrayList<Relation>());
                }
                ..get(lemma).add(rel);
            }
        }
    }
    @Override
    public Relation addRelation(String typeString functionInteger frequencySig sigList<Termterms) {
        RelationStored rel = (RelationStoredaddRelation(typefunctionfrequencyterms);
        if (sig instanceof SigStored) {
            rel.sig = (SigStoredsig;
        }
        return rel;
    }
    @Override
    public Term createTerm(Lemma lemma) {
        TermStored term = new TermStored();
        term.lemId = lemma.getID();
        return term;
    }
    @Override
    public Term createTerm(String word) {
        TermStored term = new TermStored();
        term.word = word;
        return term;
    }
    @Override
    public Sig createSig(String measuredouble value) {
        SigStored sig = new SigStored(measurevalue);
        return sig;
    }
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(" : ");
        sb.append(.toString());
        return sb.toString();
    }
New to GrepCode? Check out our FAQ X