001    /*
002     Copyright (c) 2012, Regents of the University of Colorado
003     All rights reserved.
004    
005     Redistribution and use in source and binary forms, with or without modification, 
006     are permitted provided that the following conditions are met:
007    
008     * Redistributions of source code must retain the above copyright notice, this 
009        list of conditions and the following disclaimer.
010       
011     * Redistributions in binary form must reproduce the above copyright notice, 
012        this list of conditions and the following disclaimer in the documentation 
013        and/or other materials provided with the distribution.
014       
015     * Neither the name of the University of Colorado nor the names of its 
016        contributors may be used to endorse or promote products derived from this 
017        software without specific prior written permission.
018    
019     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
022     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
023     ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
024     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
025     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
026     ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
027     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
028     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029     */
030    
031    package edu.ucdenver.ccp.esm;
032    
033    import java.util.regex.Matcher;
034    import java.util.regex.Pattern;
035    
036    /**
037     * <p>Definition of Vertex for dependency graphs</p>
038     * 
039     * <p>Vertex is then fed into graphs of the JUNG library</p>
040     * 
041     * <p>The Vertex definition can be modified based on one's own needs</p>
042     * 
043     * @author Implemented by Haibin Liu and Tested by Philippe Thomas
044     *
045     */
046    public class Vertex { 
047            /** original entire token including position number and POS tag */
048        private String token;
049        
050        /** sentence token only */
051        private String word;
052        
053        /** lemma of word */
054        private String lemma;
055    
056        /** POS tag */
057        private String tag;
058        
059        /** token position */
060        private int pos;
061        
062        /** annotation of the node */
063        private String annotation;
064        
065        /** for quick POS comparison */
066        private String generalizedPOS;
067        
068        /** for quick node comparison */
069        private String compareForm;
070        
071        /**
072             * Construtor to initialize the class field
073             */
074        public Vertex (String token) {
075            this.token = token;
076            Matcher m = Pattern.compile("^(.+)-(\\d+)\\x27*\\/(.+)$").matcher(token);       
077            if(!m.find()) 
078                    throw new RuntimeException("The node: "
079                                            + token + " is not valid. Please check.");
080            word = m.group(1);
081                pos = Integer.parseInt( m.group(2) );
082                tag = m.group(3);
083                annotation = "Component";
084        }  
085        
086        /**
087             * default Construtor to initialize the class fields to empty
088             */
089        public Vertex () {
090            annotation = "";
091                compareForm = "";
092                generalizedPOS = "";
093                lemma = "";
094                pos = 0;
095                tag = "";
096                token = "";
097                word = ""; 
098        }   
099        
100        /** 
101         * use one node's information to update another node
102         */
103        protected void update (Vertex target) {
104            annotation = target.annotation;
105                compareForm = target.compareForm;
106                generalizedPOS = target.generalizedPOS;
107                lemma = target.lemma;
108                pos = target.pos;
109                tag = target.tag;
110                token = target.token;
111                word = target.word;    
112        }
113        
114        /**
115         * retrieve original token of the node
116         * @return original token 
117         */
118        public String getToken() {
119            return token;
120        }
121        
122        /**
123         * retrieve the word of the node
124         * @return word
125         */
126        public String getWord() {
127            return word;
128        }
129        
130        /**
131         * retrieve the POS tag of the node
132         * @return POS tag
133         */
134        public String getTag() {
135            return tag;
136        }
137        
138        /**
139         * set lemma for the node
140         * @param lemma
141         */
142        public void setLemma(String lemma) {
143            this.lemma = lemma;
144        }
145        
146        /**
147         * retrieve the comparison form of the node
148         * @return comparison form
149         */
150        public String getCompareForm() {
151            return compareForm;
152        }
153        
154        /**
155         * set the comparison form of the node
156         * @param compareForm
157         */
158        public void setCompareForm(String compareForm) {
159            this.compareForm = compareForm;
160        }
161        
162        /**
163         * set the generalized POS tag of the node
164         * @param generalizedPOS
165         */
166        public void setGeneralizedPOS(String generalizedPOS) {
167            this.generalizedPOS = generalizedPOS;
168        }
169    
170            
171            /**
172             * print node content
173             */
174        @Override
175            public String toString() {
176                    return word +"-" +pos +"/" +tag;
177            }
178    }