001    /*
002     * Copyright (C) 2008-2009 Holger Arndt, A. Naegele and M. Bundschus
003     *
004     * This file is part of the Java Data Mining Package (JDMP).
005     * See the NOTICE file distributed with this work for additional
006     * information regarding copyright ownership and licensing.
007     *
008     * JDMP is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU Lesser General Public License as
010     * published by the Free Software Foundation; either version 2
011     * of the License, or (at your option) any later version.
012     *
013     * JDMP is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016     * GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public
019     * License along with JDMP; if not, write to the
020     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021     * Boston, MA  02110-1301  USA
022     */
023    
024    package org.jdmp.stanfordpos;
025    
026    import org.ujmp.core.interfaces.Wrapper;
027    import org.ujmp.core.stringmatrix.stub.AbstractDenseStringMatrix2D;
028    
029    import edu.stanford.nlp.ling.HasWord;
030    import edu.stanford.nlp.ling.Sentence;
031    import edu.stanford.nlp.ling.TaggedWord;
032    
033    public class StanfordSentenceMatrix extends AbstractDenseStringMatrix2D
034                    implements Wrapper<Sentence<? extends HasWord>> {
035            private static final long serialVersionUID = 9175120136686956227L;
036    
037            private Sentence<? extends HasWord> sentence = null;
038    
039            public StanfordSentenceMatrix(Sentence<? extends HasWord> sentence) {
040                    this.sentence = sentence;
041            }
042    
043            @Override
044            public String getString(long row, long column) {
045                    HasWord w = sentence.get((int) row);
046                    if (column == 0) {
047                            return w.word();
048                    } else {
049                            return ((TaggedWord) w).tag();
050                    }
051            }
052    
053            @Override
054            public void setString(String value, long row, long column) {
055            }
056    
057            @Override
058            public long[] getSize() {
059                    if (sentence.size() == 0) {
060                            return new long[] { 0, 0 };
061                    }
062                    if (sentence.get(0) instanceof TaggedWord) {
063                            return new long[] { sentence.size(), 2 };
064                    } else {
065                            return new long[] { sentence.size(), 1 };
066                    }
067            }
068    
069            @Override
070            public Sentence<? extends HasWord> getWrappedObject() {
071                    return sentence;
072            }
073    
074            @Override
075            public void setWrappedObject(Sentence<? extends HasWord> object) {
076                    this.sentence = object;
077            }
078    }