| package org.maltparser.ml.lib; |
|
|
| import java.io.Serializable; |
|
|
|
|
| import org.maltparser.core.helper.HashMap; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public class FeatureMap implements Serializable { |
| private static final long serialVersionUID = 7526471155622776147L; |
| private final HashMap<Long,Integer> map; |
| private int featureCounter; |
| |
| |
| |
| |
| public FeatureMap() { |
| map = new HashMap<Long, Integer>(); |
| this.featureCounter = 1; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public int addIndex(int featurePosition, int code) { |
| final long key = ((((long)featurePosition) << 48) | (long)code); |
| Integer index = map.get(key); |
| if (index == null) { |
| index = featureCounter++; |
| map.put(key, index); |
| } |
| return index.intValue(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| public int getIndex(int featurePosition, int code) { |
| final Integer index = map.get(((((long)featurePosition) << 48) | (long)code)); |
| return (index == null)?-1:index; |
| } |
| |
| |
| public int addIndex(int featurePosition, int code1, int code2) { |
| final long key = ((((long)featurePosition) << 48) | (((long)code1) << 24) | (long)code2); |
| Integer index = map.get(key); |
| if (index == null) { |
| index = featureCounter++; |
| map.put(key, index); |
| } |
| return index.intValue(); |
| } |
| |
| public int setIndex(long key, int index) { |
| return map.put(key, index); |
| } |
| |
| public int decrementIndex(Long key) { |
| Integer index = map.get(key); |
| if (index != null) { |
| map.put(key, index - 1); |
| } |
| return (index != null)?index - 1 : -1; |
| } |
| |
| public void decrementfeatureCounter() { |
| featureCounter--; |
| } |
| |
| public Integer removeIndex(long key) { |
| return map.remove(key); |
| } |
| |
| public int getIndex(int featurePosition, int code1, int code2) { |
| final Integer index = map.get(((((long)featurePosition) << 48) | (((long)code1) << 24) | (long)code2)); |
| return (index == null)?-1:index; |
| } |
| |
| |
| |
| |
| public int size() { |
| return map.size(); |
| } |
| |
| |
| public Long[] reverseMap() { |
| Long[] reverseMap = new Long[map.size() +1]; |
|
|
| for (Long key : map.keySet()) { |
| reverseMap[map.get(key)] = key; |
| } |
| return reverseMap; |
| } |
| |
| |
| |
| public void setFeatureCounter(int featureCounter) { |
| this.featureCounter = featureCounter; |
| } |
|
|
| |
| |
| |
| public int getFeatureCounter() { |
| return featureCounter; |
| } |
| } |
|
|