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) University of Tübingen. 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.tc.xb;
 
 import java.util.List;

Author(s):
Yana Panchenko
 
 public class ReferencesLayerStored extends TextCorpusLayerStoredAbstract implements ReferencesLayer {
 
     public static final String XML_NAME = "references";
     @XmlAttribute(name = "typetagset")
     protected String typetagset;
     @XmlAttribute(name = "reltagset")
     protected String reltagset;
     @XmlAttribute(name = "extrefs")
     protected String externalReferenceSource;
 
     protected void setLayersConnector(TextCorpusLayersConnector connector) {
         this. = connector;
         for (ReferencedEntityStored r : ) {
             for (ReferenceStored ref : r.references) {
                 connector.referenceId2ItsReference.put(ref.idref);
                 for (String tokRef : ref.tokRefs) {
                     //connector.token2ItsReferent.put(connector.tokenId2ItsToken.get(tokRef), r);
                     Token tok = connector.tokenId2ItsToken.get(tokRef);
                     if (!connector.token2ItsReferent.containsKey(tok)) {
                         connector.token2ItsReferent.put(toknew ArrayList<ReferencedEntity>());
                     }
                     connector.token2ItsReferent.get(tok).add(r);
                 }
             }
         }
     }
 
     protected ReferencesLayerStored() {
     }
 
     protected ReferencesLayerStored(TextCorpusLayersConnector connector) {
         this. = connector;
     }
 
     @Override
     public boolean isEmpty() {
         return .isEmpty();
     }
 
     @Override
     public int size() {
         return .size();
     }
 
     @Override
     public String getTypetagset() {
         return ;
     }
 
     @Override
     public String getReltagset() {
         return ;
     }
 
     @Override
     public boolean hasExternalReferences() {
        return (this. != null);
    }
    @Override
        return this.;
    }
    @Override
    public ReferencedEntity getReferencedEntity(int index) {
        return .get(index);
    }
    @Override
        return this...get(token);
    }
    @Override
    public Token[] getTokens(Reference reference) {
        if (reference instanceof ReferenceStored) {
            ReferenceStored cor = (ReferenceStoredreference;
            return WlfUtilities.tokenIdsToTokens(cor.tokRefs.);
        }
        return null;
    }
    @Override
    public Token[] getMinimumTokens(Reference reference) {
        if (reference instanceof ReferenceStored) {
            ReferenceStored cor = (ReferenceStoredreference;
            return WlfUtilities.tokenIdsToTokens(cor.minTokRefs.);
        }
        return null;
    }
    @Override
    public Reference[] getTarget(Reference reference) {
        if (reference instanceof ReferenceStored) {
            ReferenceStored ref = (ReferenceStoredreference;
            Reference[] targetRefs = new Reference[ref.targetIds.length];
            for (int i = 0; i < targetRefs.lengthi++) {
                targetRefs[i] = ..get(ref.targetIds[i]);
            }
            return targetRefs;
        }
        return null;
    }
    @Override
    public ReferencedEntity addReferent(List<Referencereferences) {
        return addReferent(referencesnull);
    }
    @Override
    public ReferencedEntity addReferent(List<ReferencereferencesString externalId) {
        ReferencedEntityStored referent = new ReferencedEntityStored();
        if (externalId != null) {
            referent.externalRef = new ExternalReferenceStored(externalId);
        }
        for (Reference ref : references) {
            addReference(referentref);
        }
        .add(referent);
        return referent;
    }
    private void addReference(ReferencedEntityStored referentReference reference) {
        if (reference instanceof ReferenceStored) {
            ReferenceStored ref = (ReferenceStoredreference;
            referent.references.add(ref);
            for (String tokRef : ref.tokRefs) {
                Token tok = ..get(tokRef);
                if (!..containsKey(tok)) {
                    ..put(toknew ArrayList<ReferencedEntity>());
                }
                ..get(tok).add(referent);
            }
        }
    }
    @Override
    public Reference createReference(List<TokenreferenceTokens) {
        return createReference(nullreferenceTokensnull);
    }
    @Override
    public Reference createReference(List<TokenreferenceTokensList<TokenminReferenceTokens) {
        return createReference(nullreferenceTokensminReferenceTokens);
    }
    @Override
    public Reference createReference(String typeList<TokenreferenceTokens,
            List<TokenminReferenceTokens) {
        ReferenceStored reference = new ReferenceStored();
        reference.id = . + ..size();
        ..put(reference.idreference);
        reference.type = type;
        reference.tokRefs = WlfUtilities.tokens2TokenIds(referenceTokens);
        if (minReferenceTokens != null) {
            reference.minTokRefs = WlfUtilities.tokens2TokenIds(minReferenceTokens);
        }
        return reference;
    }
    @Override
    public void addRelation(Reference referenceString relationReference... target) {
        if (reference instanceof ReferenceStored) {
            ReferenceStored ref = (ReferenceStoredreference;
            ref.relation = relation;
            ref.targetIds = new String[target.length];
            for (int i = 0; i < target.lengthi++) {
                if (target[iinstanceof ReferenceStored) {
                    ref.targetIds[i] = ((ReferenceStoredtarget[i]).;
                }
            }
        }
    }
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(" {");
        if ( != null) {
            sb.append(this.);
        }
        if ( != null) {
            sb.append(" ").append(this.);
        }
        if (this. != null) {
            sb.append(" ").append(this.);
        }
        sb.append("}: ");
        sb.append(.toString());
        return sb.toString();
    }
New to GrepCode? Check out our FAQ X