Java Code Examples for gnu.trove.THashSet#contains()

The following examples show how to use gnu.trove.THashSet#contains() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArchivesBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static <T> String addParentDirectories(@Nonnull T archiveObject,
                                               @Nonnull ArchivePackageWriter<T> writer,
                                               THashSet<String> writtenPaths,
                                               String relativePath) throws IOException {
  while (StringUtil.startsWithChar(relativePath, '/')) {
    relativePath = relativePath.substring(1);
  }
  int i = relativePath.indexOf('/');
  while (i != -1) {
    String prefix = relativePath.substring(0, i + 1);
    if (!writtenPaths.contains(prefix) && prefix.length() > 1) {

      writer.addDirectory(archiveObject, prefix);

      writtenPaths.add(prefix);
    }
    i = relativePath.indexOf('/', i + 1);
  }
  return relativePath;
}
 
Example 2
Source File: WordNetRelations.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
public THashSet<String> getAllPossibleRelationSubset(String sWord)
{
	//putting stuff into the map
	getAllRelatedWords(sWord);
	
	THashSet<String> result =  new THashSet<String>();
	result.add(new String(NO_RELATION));
	
	/*
	 * workingRelatedWords contains all the related words
	 */
	Iterator<String> itr = workingRelatedWords.iterator();		
	while(itr.hasNext())
	{
		Set<String> relations = getRelations(sWord,itr.next());
		String[] array = new String[relations.size()];
		relations.toArray(array);
		Arrays.sort(array);
		String concat = "";
		for(String rel: array)
		{
			concat+=rel+":";
		}
		if(!result.contains(concat))
		{
			result.add(concat);
		}
	}
	
	return result;
}
 
Example 3
Source File: LexicalUnitsFrameExtraction.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Populates the given map object with frames (as keys) and sets of target words that evoke 
 * those frames in the given corresponding sentences (as values)
 * @param map
 * @param frames
 * @param sentences
 * @author dipanjan
 */
public static void fillMap(THashMap<String,THashSet<String>> map, ArrayList<String> frames, ArrayList<String> sentences)
{
	int size = frames.size();
	for(int i = 0; i < size; i ++)
	{
		String line = frames.get(i);
		String[] toks = line.split("\t");
		int sentenceNum = new Integer(toks[toks.length-1]);
		String storedSentence = sentences.get(sentenceNum);
		String frame = toks[0];
		String tokenNums = toks[2];
		String[] nums = tokenNums.split("_");
		String lexicalUnits = getTokens(storedSentence,nums);
		THashSet<String> set = map.get(frame);	
		if(set==null)
		{
			set = new THashSet<String>();
			set.add(lexicalUnits);
			map.put(frame, set);
		}
		else
		{
			if(!set.contains(lexicalUnits))
			{
				set.add(lexicalUnits);
			}
		}
	}
}
 
Example 4
Source File: Decoding.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isThereOverlap(String spans,THashSet<String> seenSpans)
{
	String[] toks = spans.split(":");
	for(int i = 0; i < toks.length-1; i ++)
	{
		for(int j = i +1; j < toks.length; j ++)
		{
			if(pairwiseOverlap(toks[i],toks[j]))
				return true;
			if(seenSpans.contains(toks[i])||seenSpans.contains(toks[j]))
				return true;
		}
	}
	return false;
}
 
Example 5
Source File: PathInternerTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void checkTrove(HashSet<String> hs, THashSet<String> thm) {
  for (String s : hs) {
    if (!thm.contains(new String(s))) {
      throw new AssertionError();
    }
  }
}
 
Example 6
Source File: VcsDirtyScopeImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean isInDirtyFiles(final FilePath path) {
  final VcsRoot rootObject = myVcsManager.getVcsRootObjectFor(path);
  if (rootObject != null && myVcs.equals(rootObject.getVcs())) {
    final THashSet<FilePath> files = myDirtyFiles.get(rootObject.getPath());
    if (files != null && files.contains(path)) return true;
  }
  return false;
}
 
Example 7
Source File: ScrapTest.java    From semafor-semantic-parser with GNU General Public License v3.0 4 votes vote down vote up
public static void compareTotalNumberOfSpansInThreeSettings()
{
	THashSet<String> spanSet = getSpans();
	String parseFile = "lrdata/semeval.fulltrain.sentences.lemma.tags";
	ArrayList<String> allParses = ParsePreparation.readSentencesFromFile(parseFile);
	int bruteForce = 0;
	int subtreesOnly = 0;
	int subtreesPlusUnlabeled = 0;
	for(String parsedSent:allParses)
	{
		StringTokenizer st = new StringTokenizer(parsedSent,"\t");
		int tokensInFirstSent = new Integer(st.nextToken());
		String[][] data = new String[5][tokensInFirstSent];
		for(int k = 0; k < 5; k ++)
		{
			data[k]=new String[tokensInFirstSent];
			for(int j = 0; j < tokensInFirstSent; j ++)
			{
				data[k][j]=""+st.nextToken().trim();
			}
		}	
		DependencyParse parseS = DependencyParse.processFN(data, 0.0);
		DependencyParse[] sortedNodes = DependencyParse.getIndexSortedListOfNodes(parseS);
		boolean[][] spanMat = new boolean[sortedNodes.length][sortedNodes.length];
		int[][] heads = new int[sortedNodes.length][sortedNodes.length];
		findSpans(spanMat,heads,sortedNodes);
		for(int j = 0; j < tokensInFirstSent; j ++)
		{
			for(int k = 0; k < tokensInFirstSent; k ++)
			{
				if(k<j)
					continue;
				bruteForce++;
				if(j==k)
					continue;
				if(spanMat[j][k])
					subtreesOnly++;
				String span = "";
				for(int l = j; l <= k; l ++)
					span+= data[0][l]+" ";
				span=span.trim().toLowerCase();
				if(spanSet.contains(span))
				{
					if(!spanMat[j][k])
						subtreesPlusUnlabeled++;
					spanMat[j][k]=true;
				}
			}
		}
	}
	
	System.out.println("Brute force:"+bruteForce);
	System.out.println("Subtrees only:"+subtreesOnly);
	System.out.println("Subtrees plus unlabeled data:"+subtreesPlusUnlabeled);
}
 
Example 8
Source File: ScrapTest.java    From semafor-semantic-parser with GNU General Public License v3.0 4 votes vote down vote up
public static void testCoverageWithUnlabeledData(THashSet<String> spanSet)
{
	String parseFile = "lrdata/semeval.fulltrain.sentences.lemma.tags";
	String feFile = "lrdata/semeval.fulltrain.sentences.frame.elements";
	ArrayList<String> parses = ParsePreparation.readSentencesFromFile(parseFile);
	ArrayList<String> feLines = ParsePreparation.readSentencesFromFile(feFile);
			
	int match=0;
	int total=0;
	for(String feLine:feLines)
	{
		System.out.println(feLine);
		String[] toks = feLine.trim().split("\t");
		int sentNum = new Integer(toks[5]);
		StringTokenizer st = new StringTokenizer(parses.get(sentNum),"\t");
		int tokensInFirstSent = new Integer(st.nextToken());
		String[][] data = new String[5][tokensInFirstSent];
		for(int k = 0; k < 5; k ++)
		{
			data[k]=new String[tokensInFirstSent];
			for(int j = 0; j < tokensInFirstSent; j ++)
			{
				data[k][j]=""+st.nextToken().trim();
			}
		}	
		DependencyParse parseS = DependencyParse.processFN(data, 0.0);
		DependencyParse[] sortedNodes = DependencyParse.getIndexSortedListOfNodes(parseS);
		boolean[][] spanMat = new boolean[sortedNodes.length][sortedNodes.length];
		int[][] heads = new int[sortedNodes.length][sortedNodes.length];
		
		findSpans(spanMat,heads,sortedNodes);
					
		for(int j = 0; j < tokensInFirstSent; j ++)
		{
			for(int k = 0; k < tokensInFirstSent; k ++)
			{
				if(j==k)
					continue;
				if(k<j)
					continue;
				String span = "";
				for(int l = j; l <= k; l ++)
					span+= data[0][l]+" ";
				span=span.trim().toLowerCase();
				if(spanSet.contains(span))
					spanMat[j][k]=true;
			}
		}
		
		
		for(int k = 6; k < toks.length; k = k + 2)
		{
			String[] spans = toks[k+1].split(":");
			int start = -1;
			int end = -1;
			if(spans.length==1)
			{
				start=new Integer(spans[0]);
				end=new Integer(spans[0]);
			}
			else
			{
				start=new Integer(spans[0]);
				end=new Integer(spans[1]);
			}
			if(spanMat[start][end])
				match++;
			total++;
		}
	}
	double recall = (double)match/total;
	System.out.println("Recall:"+recall);
	
}
 
Example 9
Source File: LinDekNeighbors.java    From semafor-semantic-parser with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isMultiWordAdjective(THashSet<String> mAdjectives, 
		String word) {
	return mAdjectives.contains(word);
}
 
Example 10
Source File: LinDekNeighbors.java    From semafor-semantic-parser with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isMultiWordAdverb(THashSet<String> mAdverbs, 
		String word) {
	return mAdverbs.contains(word);	
}
 
Example 11
Source File: PathInternerTest.java    From consulo with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
public static void main(String[] args) throws InterruptedException, IOException {
  final HashSet<String> hs = new HashSet<String>();
  FileUtil.processFilesRecursively(new File(ContainerPathManager.get().getHomePath()), new Processor<File>() {
    @Override
    public boolean process(File file) {
      hs.add(file.getPath());
      return true;
    }
  });
  THashSet<String> thm = new THashSet<String>();
  PathInterner.PathEnumerator interner = new PathInterner.PathEnumerator();
  for (String s : hs) {
    thm.add(s);
    if (!thm.contains(s)) {
      throw new AssertionError();
    }
    interner.addPath(s);
    if (!interner.containsPath(s)) {
      throw new AssertionError(s);
    }
  }
  System.out.println("Map collected, press when ready");

  BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  reader.readLine();

  System.out.println("Filling THashSet...");
  long start = System.currentTimeMillis();
  checkTrove(hs, thm);
  System.out.println("done " + (System.currentTimeMillis() - start));

  System.out.println("Filling PathInterner...");
  start = System.currentTimeMillis();
  checkInterner(hs, interner);
  System.out.println("done " + (System.currentTimeMillis() - start));
  hs.clear();
  System.out.println("press when ready");

  reader.readLine();

  System.out.println("interner.hashCode() = " + interner.hashCode());
  System.out.println("thm.hashCode() = " + thm.hashCode());
}