001    // Copyright 2012, 2013 Brad Block, Pawjaw, LLC. (an Ohio Limited Liability Company)
002    // 
003    // This file is part of JBTCRF.
004    // 
005    // JBTCRF is free software: you can redistribute it and/or modify
006    // it under the terms of the GNU General Public License as published by
007    // the Free Software Foundation, either version 3 of the License, or
008    // (at your option) any later version.
009    // 
010    // JBTCRF is distributed in the hope that it will be useful,
011    // but WITHOUT ANY WARRANTY; without even the implied warranty of
012    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013    // GNU General Public License for more details.
014    // 
015    // You should have received a copy of the GNU General Public License
016    // along with JBTCRF.  If not, see <http://www.gnu.org/licenses/>.
017    
018    package com.pawjaw.classification.crf.lmcbt.points;
019    
020    import com.pawjaw.classification.crf.lmcbt.configurations.Configuration;
021    
022    public class DensePoint implements Point {
023        private int[] posfs;
024        private boolean[] feature_f;
025    
026        public void setFeatures(boolean[] bs) {
027            int f, F = bs.length, n = 0, N = 0;
028            this.feature_f = bs;
029            for(f = 0;f < F;f++)
030                if(bs[f])
031                    N++;
032            posfs = new int[N];
033            for(f = 0;f < F;f++)
034                if(bs[f])
035                    posfs[n++] = f;
036        }
037    
038        public boolean hasTrueFeature(Configuration c, int feature_index) {
039            return feature_f[feature_index];
040        }
041    
042        public int nextTrueFeature(Configuration c, int offset) {
043            if(offset < 0 || offset >= posfs.length)
044                return -1;
045            else
046                return posfs[offset];
047        }
048    
049        public int trueFeatureCount() {
050            return posfs.length;
051        }
052    }