All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.berkeley.nlp.util.ConcatenationMap Maven / Gradle / Ivy

Go to download

The Berkeley parser analyzes the grammatical structure of natural language using probabilistic context-free grammars (PCFGs).

The newest version!
package edu.berkeley.nlp.util;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Union of two maps (sort of). Doesn't handle duplicate keys (keys in both
 * maps). Unmodifiable.
 * 
 * @author adampauls
 * 
 * @param 
 */
public class ConcatenationMap extends AbstractMap
{
	private Set> entrySet;

	@Override
	public Set> entrySet()
	{
		if (entrySet == null)
		{
			List>> list = new ArrayList>>();
			for (Map map : maps)
			{
				list.add(map.entrySet());
			}
			entrySet = new ConcatenationSet>(list);
		}
		return entrySet;
	}

	@Override
	public V get(Object arg0)
	{
		for (Map map : maps)
		{
			V v = map.get(arg0);
			if (v != null) return v;
		}
		return null;
	}



	@Override
	public boolean containsKey(Object arg0)
	{
		for (Map map : maps)
		{
			if (map.containsKey(arg0)) return true;
		}
		return false;
	}

	private Collection> maps;

	private int size = 0;

	public ConcatenationMap(Collection> maps)
	{
		this.maps = maps;
		for (Map set : maps)
		{

			size += set.size();
		}
	}

	
	
	@Override
	public int size()
	{
		return size;

	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy