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

The following examples show how to use gnu.trove.THashSet#add() . 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 <T> void addFileToArchive(@Nonnull T archiveObject,
                                  @Nonnull ArchivePackageWriter<T> writer,
                                  @Nonnull File file,
                                  @Nonnull String relativePath,
                                  @Nonnull THashSet<String> writtenPaths) throws IOException {
  if (!file.exists()) {
    return;
  }

  if (!FileUtil.isFilePathAcceptable(file, myFileFilter)) {
    return;
  }

  if (!writtenPaths.add(relativePath)) {
    return;
  }

  relativePath = addParentDirectories(archiveObject, writer, writtenPaths, relativePath);

  myContext.getProgressIndicator().setText2(relativePath);

  try (FileInputStream fileOutputStream = new FileInputStream(file)) {
    writer.addFile(archiveObject, fileOutputStream, relativePath, file.length(), file.lastModified());
  }
}
 
Example 2
Source File: ScrapTest.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public static THashSet<String> getSpans()
{
	THashSet<String> spans = new THashSet<String>();
	try
	{
		String line = null;
		BufferedReader bReader = new BufferedReader(new FileReader("lrdata/matched_spans"));
		while((line=bReader.readLine())!=null)
		{
			String[] toks = line.trim().split("\t");
			char first = toks[0].charAt(0);
			if((first>='a'&&first<='z')||(first>='A'&&first<='Z')||(first>='0'&&first<='9'))
			{
				spans.add(toks[0].trim());
			}
		}
		bReader.close();
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	return spans;
}
 
Example 3
Source File: ScrapTest.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public static THashSet<String> getSpans(String file)
{
	THashSet<String> spans = new THashSet<String>();
	try
	{
		String line = null;
		BufferedReader bReader = new BufferedReader(new FileReader(file));
		while((line=bReader.readLine())!=null)
		{
			String[] toks = line.trim().split("\t");
			char first = toks[0].charAt(0);
			if((first>='a'&&first<='z')||(first>='A'&&first<='Z')||(first>='0'&&first<='9'))
			{
				spans.add(toks[0].trim());
			}
		}
		bReader.close();
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	return spans;
}
 
Example 4
Source File: ArchivesBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
private <T> void extractFileAndAddToArchive(@Nonnull T archiveObject,
                                            @Nonnull ArchivePackageWriter<T> writer,
                                            VirtualFile sourceFile,
                                            String relativePath,
                                            THashSet<String> writtenPaths) throws IOException {
  relativePath = addParentDirectories(archiveObject, writer, writtenPaths, relativePath);
  myContext.getProgressIndicator().setText2(relativePath);
  if (!writtenPaths.add(relativePath)) return;

  Pair<InputStream, Long> streamLongPair = ArtifactCompilerUtil.getArchiveEntryInputStream(sourceFile, myContext);
  final InputStream input = streamLongPair.getFirst();
  if (input == null) {
    return;
  }

  try {
    writer.addFile(archiveObject, input, relativePath, streamLongPair.getSecond(), ArtifactCompilerUtil.getArchiveFile(sourceFile).lastModified());
  }
  finally {
    input.close();
  }
}
 
Example 5
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 6
Source File: WordNetRelations.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
private THashSet<String> getRelationWN()
{
	THashSet<String> result = new THashSet<String>();
	if(!workingRelatedWords.contains(targetWord))
	{
		result.add(NO_RELATION);
		return result;
	}
	Set<String> keys  = workingRelationSet.keySet();
	Iterator<String> keyIterator = keys.iterator();
	while(keyIterator.hasNext())
	{
		String key = keyIterator.next();
		Set<String> words = workingRelationSet.get(key);
		if(words.contains(targetWord))
			result.add(key);
	}			
	
	return result;
}
 
Example 7
Source File: FeatureExtractor.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public Set<String> getWNRelations(THashMap<String, THashSet<String>> wnCacheMap,String sWord, String tWord, WordNetRelations wnr)
{
	String pair = sWord.toLowerCase()+"\t"+tWord.toLowerCase();
	if(wnCacheMap==null)
	{
		return wnr.getRelations(sWord.toLowerCase(), tWord.toLowerCase());
	}
	else if(!wnCacheMap.contains(pair))
	{
		Set<String> relations = wnr.getRelations(sWord.toLowerCase(), tWord.toLowerCase());
		if(relations.contains(WordNetRelations.NO_RELATION))
			return relations;
		else
		{
			THashSet<String> nR = new THashSet<String>();
			for(String string:relations)
				nR.add(string);
			wnCacheMap.put(pair, nR);
			return relations;
		}
	}
	else
	{
		return wnCacheMap.get(pair);
	}
}
 
Example 8
Source File: UniqueVFilePathBuilderImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static UniqueNameBuilder<VirtualFile> filesWithTheSameName(String fileName, Project project,
                                                                   boolean skipNonOpenedFiles,
                                                                   GlobalSearchScope scope) {
  Collection<VirtualFile> filesWithSameName = skipNonOpenedFiles ? Collections.emptySet() :
                                              FilenameIndex.getVirtualFilesByName(project, fileName,
                                                                                  scope);
  THashSet<VirtualFile> setOfFilesWithTheSameName = new THashSet<>(filesWithSameName);
  // add open files out of project scope
  for(VirtualFile openFile: FileEditorManager.getInstance(project).getOpenFiles()) {
    if (openFile.getName().equals(fileName)) {
      setOfFilesWithTheSameName.add(openFile);
    }
  }
  if (!skipNonOpenedFiles) {
    for (VirtualFile recentlyEditedFile : EditorHistoryManager.getInstance(project).getFiles()) {
      if (recentlyEditedFile.getName().equals(fileName)) {
        setOfFilesWithTheSameName.add(recentlyEditedFile);
      }
    }
  }

  filesWithSameName = setOfFilesWithTheSameName;

  if (filesWithSameName.size() > 1) {
    String path = project.getBasePath();
    path = path == null ? "" : FileUtil.toSystemIndependentName(path);
    UniqueNameBuilder<VirtualFile> builder = new UniqueNameBuilder<>(path, File.separator, 25);
    for (VirtualFile virtualFile: filesWithSameName) {
      builder.addPath(virtualFile, virtualFile.getPath());
    }
    return builder;
  }
  return null;
}
 
Example 9
Source File: MultiCounter.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<java.util.Map.Entry<String, Counter<K>>> entrySet() {
	THashSet<java.util.Map.Entry<String,Counter<K>>> entries = new THashSet<java.util.Map.Entry<String,Counter<K>>>();
	for (int i=0; i<counters.length; i++) {
		entries.add(new java.util.AbstractMap.SimpleEntry<String,Counter<K>>(counterNames[i], counters[i]));
	}
	return entries;
}
 
Example 10
Source File: RequiredDataCreation.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
public static Set<String> getRevisedSet(Set<String> rl, boolean check)
{
	THashSet<String> result = new THashSet<String>();
	for(String r: rl)
	{
		r=r.toLowerCase();
		if(check)
		{
			StringTokenizer st = new StringTokenizer(r," ");
			if(st.countTokens()>1)
				continue;
		}
		if(r.contains("_"))
		{
			if(check)
				continue;
			String[] toks = r.split("_");
			r = "";
			for(int i = 0; i < toks.length; i ++)
			{
				r+=toks[i]+" ";
			}
			r=r.trim();
		}
		result.add(r);
	}		
	return result;
}
 
Example 11
Source File: HighlightCommand.java    From CppTools with Apache License 2.0 5 votes vote down vote up
private static RangeHighlighter processHighlighter(int hFrom, int hTo, int colorIndex, TextAttributes attrs,
                                                   Editor editor, TIntObjectHashMap<RangeHighlighter> lastOffsetToMarkersMap,
                                                   THashSet<RangeHighlighter> highlightersSet,
                                                   THashSet<RangeHighlighter> invalidMarkersSet
                                                   ) {
  RangeHighlighter rangeHighlighter = lastOffsetToMarkersMap.get(hFrom);

  if (rangeHighlighter == null ||
      rangeHighlighter.getEndOffset() != hTo ||
      rangeHighlighter.getTextAttributes() != attrs
      ) {
    highlightersSet.add(
      rangeHighlighter = HighlightUtils.createRangeMarker(
        editor,
        hFrom,
        hTo,
        colorIndex,
        attrs
      )
    );

    lastOffsetToMarkersMap.put(hFrom, rangeHighlighter);
  } else {
    highlightersSet.add(rangeHighlighter);
    invalidMarkersSet.remove(rangeHighlighter);
  }

  return rangeHighlighter;
}
 
Example 12
Source File: WordNetRelationsCache.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
public static void createMap()
{
	String textFile = "/mal2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/hierWnCache";
	String wnRelationsMapFile = "/mal2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/hierWnCacheRelations.ser";
	
	THashMap<String,THashSet<String>> map = new THashMap<String,THashSet<String>>();
	try
	{
		BufferedReader bReader = new BufferedReader(new FileReader(textFile));
		String line = null;
		int count = 0;
		while((line=bReader.readLine())!=null)
		{
			String[] toks = line.split("\t");
			String hiddenWord = toks[0].trim();
			String actualWord = toks[1].trim();
			String relations = toks[2].trim();
			String key = hiddenWord+"\t"+actualWord;
			String[] relationToks = relations.split(" ");
			THashSet<String> relSet = new THashSet<String>();
			for(int i = 0; i < relationToks.length; i ++)
			{
				relSet.add(relationToks[i]);
			}
			map.put(key, relSet);
			if(count%1000==0)
				System.out.println(count);
			count++;
		}
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	SerializedObjects.writeSerializedObject(map, wnRelationsMapFile);
}
 
Example 13
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 14
Source File: CompletionContributor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected List<CompletionContributor> buildExtensions(String stringKey, Language key) {
  final THashSet<String> allowed = new THashSet<String>();
  while (key != null) {
    allowed.add(keyToString(key));
    key = key.getBaseLanguage();
  }
  allowed.add("any");
  return buildExtensions(allowed);
}
 
Example 15
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 16
Source File: StringSetDataExternalizer.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public synchronized Set<String> read(@NotNull DataInput in) throws IOException {
    THashSet set = new THashSet();

    for(int r = in.readInt(); r > 0; --r) {
        set.add(EnumeratorStringDescriptor.INSTANCE.read(in));
    }

    return set;
}
 
Example 17
Source File: LookupElementBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Contract(value = "", pure = true)
public LookupElementBuilder withLookupString(@Nonnull String another) {
  final THashSet<String> set = new THashSet<>(myAllLookupStrings);
  set.add(another);
  return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, myRenderer, myHardcodedPresentation, Collections.unmodifiableSet(set), myCaseSensitive);
}
 
Example 18
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());
}
 
Example 19
Source File: WordNetRelations.java    From semafor-semantic-parser with GNU General Public License v3.0 4 votes vote down vote up
private THashMap<String, Set<String>> collapseFinerRelations(Map<RelationType, Set<String>> rel)
{
	THashMap<String,Set<String>> result = new THashMap<String,Set<String>>();
	THashSet<String> identity = new THashSet<String>();
	THashSet<String> synonym = new THashSet<String>();
	THashSet<String> antonym = new THashSet<String>();
	THashSet<String> hypernym = new THashSet<String>();
	THashSet<String> hyponym = new THashSet<String>();
	THashSet<String> derivedForm = new THashSet<String>();
	THashSet<String> morphSet = new THashSet<String>();
	THashSet<String> verbGroup = new THashSet<String>();
	THashSet<String> entailment = new THashSet<String>();
	THashSet<String> entailedBy = new THashSet<String>();
	THashSet<String> seeAlso = new THashSet<String>();
	THashSet<String> causalRelation = new THashSet<String>();
	THashSet<String> sameNumber = new THashSet<String>();
	
	identity.addAll(rel.get(RelationType.idty));
	synonym.addAll(rel.get(RelationType.synm)); synonym.addAll(rel.get(RelationType.syn2));
	antonym.addAll(rel.get(RelationType.antm)); antonym.addAll(rel.get(RelationType.extd)); antonym.addAll(rel.get(RelationType.indi));
	hypernym.addAll(rel.get(RelationType.hype));
	hyponym.addAll(rel.get(RelationType.hypo));
	derivedForm.addAll(rel.get(RelationType.derv));
	morphSet.addAll(rel.get(RelationType.morph));
	verbGroup.addAll(rel.get(RelationType.vgrp));
	entailment.addAll(rel.get(RelationType.entl));
	entailedBy.addAll(rel.get(RelationType.entlby));
	seeAlso.addAll(rel.get(RelationType.alsoc));
	causalRelation.addAll(rel.get(RelationType.cause));
	if(sourceWord==null)
	{
		System.out.println("Problem. Source Word Null. Exiting");
		System.exit(0);
	}
	if(sourceWord.charAt(0)>='0'&&sourceWord.charAt(0)<='9')
		sameNumber.add(sourceWord);
	
	
	result.put("identity",identity);
	result.put("synonym",synonym);
	result.put("antonym",antonym);
	result.put("hypernym",hypernym);
	result.put("hyponym",hyponym);
	result.put("derived-form",derivedForm);
	result.put("morph",morphSet);
	result.put("verb-group",verbGroup);
	result.put("entailment",entailment);
	result.put("entailed-by",entailedBy);
	result.put("see-also",seeAlso);
	result.put("causal-relation",causalRelation);
	result.put("same-number", sameNumber);
	
	return result;
}
 
Example 20
Source File: AllPossibleSpansSemEval.java    From semafor-semantic-parser with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args)
{
	String[] files = {"lrdata/semeval.fulltrain.sentences",
					  "lrdata/semeval.fulldev.sentences",
					  "/usr2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/semeval.fulltest.sentences"
					 };
	THashSet<String> arguments = new THashSet<String>();
	for(int i = 0; i < 3; i ++)
	{
		ArrayList<String> sents = ParsePreparation.readSentencesFromFile(files[i]);
		for(String sent:sents)
		{
			StringTokenizer st = new StringTokenizer(sent," \t",true);
			ArrayList<String> tokens = new ArrayList<String>();
			while(st.hasMoreTokens())
			{
				String tok = st.nextToken().trim();
				if(tok.equals(""))
					continue;
				tokens.add(tok);
			}
			String[] arr = new String[tokens.size()];
			tokens.toArray(arr);
			for(int j = 0; j < arr.length; j ++)
			{
				for(int k = 0; k < arr.length; k ++)
				{
					if(j==k)
						continue;
					if(k<j)
						continue;
					String span = "";
					for(int l = j; l <= k; l ++)
						span+= arr[l]+" ";
					span=span.trim().toLowerCase();
					System.out.println(span);
					arguments.add(span);
				}
			}
		}
	}
	String[] allSpans = new String[arguments.size()];
	arguments.toArray(allSpans);
	Arrays.sort(allSpans);
	try
	{
		BufferedWriter bWriter = new BufferedWriter(new FileWriter("lrdata/allSemEvalSpans"));
		for(int i = 0; i < allSpans.length; i ++)
		{
			bWriter.write(allSpans[i]+"\n");
		}
		bWriter.close();
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	
}