Java Code Examples for gnu.trove.TObjectIntHashMap#get()

The following examples show how to use gnu.trove.TObjectIntHashMap#get() . 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: LinDekNeighbors.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public static int findWordPOS(TObjectIntHashMap<String> dAdjectives, 
		TObjectIntHashMap<String> dAdverbs,
		String word) {
	int adjCount = dAdjectives.get(word);
	int advCount = dAdverbs.get(word);

	if (adjCount == 0 && advCount == 0) {
		if (word.endsWith("ly")) 
			return 2;
		else {
			return 3;
		}				
	}
	int total = adjCount + advCount;
	double adjProb = (double)adjCount / (double) total;
	double advProb = (double)advCount / (double) total;
	if (Math.abs(adjProb - advProb) < 0.2) {
		return 3;
	} else {
		if (adjProb > advProb) {
			return 1;
		} else {
			return 2;
		}
	}
}
 
Example 2
Source File: ExpandedSupModel.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
	String supmodel = args[0];
	String supalphabet = args[1];
	String ssalphabet = args[2];
	String outmodel = args[3];
	
	TIntObjectHashMap<String> supAlphabet = 
		readAlphabet(supalphabet);
	TObjectIntHashMap<String> rSupAlphabet = getReverseMap(supAlphabet);
	TIntObjectHashMap<String> ssAlphabet = 
		readAlphabet(ssalphabet);
	int supsize = supAlphabet.size();
	int sssize = ssAlphabet.size();
	double[] supmodelarr = readDoubleArray(supmodel, supsize+1);
	double[] ssmodelarr = new double[sssize+1];
	ssmodelarr[0] = supmodelarr[0];
	for (int i = 1; i < sssize+1; i++) {
		String feat = ssAlphabet.get(i);
		if (rSupAlphabet.contains(feat)) {
			int index = rSupAlphabet.get(feat);
			ssmodelarr[i] = supmodelarr[index];
		} else {
			ssmodelarr[i] = 1.0;
		}
	}
	writeArray(ssmodelarr, outmodel);
}
 
Example 3
Source File: ConvertGraphToSerObj.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
public static int indexString(String string, TObjectIntHashMap<String> map, ArrayList<String> list) {
	if (map.contains(string)) {
		return map.get(string);
	} else {
		int size = map.size();
		map.put(string, size);
		list.add(string);
		return size;
	}
}
 
Example 4
Source File: MessageCounter.java    From consulo with Apache License 2.0 5 votes vote down vote up
public synchronized int getCount(@Nullable final String groupName,
                                 @Nonnull final NotificationSource notificationSource,
                                 @Nullable final NotificationCategory notificationCategory,
                                 @Nonnull final ProjectSystemId projectSystemId) {
  int count = 0;
  final Map<String, Map<NotificationSource, TObjectIntHashMap<NotificationCategory>>> groupMap = ContainerUtil.getOrElse(
          map,
          projectSystemId,
          Collections.<String, Map<NotificationSource, TObjectIntHashMap<NotificationCategory>>>emptyMap());

  for (Map.Entry<String, Map<NotificationSource, TObjectIntHashMap<NotificationCategory>>> entry : groupMap.entrySet()) {
    if (groupName == null || groupName.equals(entry.getKey())) {
      final TObjectIntHashMap<NotificationCategory> counter = entry.getValue().get(notificationSource);
      if (counter == null) continue;

      if (notificationCategory == null) {
        for (int aCount : counter.getValues()) {
          count += aCount;
        }
      }
      else {
        count = counter.get(notificationCategory);
      }
    }
  }

  return count;
}
 
Example 5
Source File: KShortestPathsFinder.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void computeDistancesToTarget() {
  myNonTreeEdges = new MultiMap<Node, GraphEdge<Node>>();
  mySortedNodes = new ArrayList<Node>();
  myNextNodes = new HashMap<Node, Node>();
  TObjectIntHashMap<Node> distances = new TObjectIntHashMap<Node>();
  Deque<Node> nodes = new ArrayDeque<Node>();
  nodes.addLast(myFinish);
  distances.put(myFinish, 0);
  while (!nodes.isEmpty()) {
    myProgressIndicator.checkCanceled();
    Node node = nodes.removeFirst();
    mySortedNodes.add(node);
    int d = distances.get(node) + 1;
    Iterator<Node> iterator = myGraph.getIn(node);
    while (iterator.hasNext()) {
      Node prev = iterator.next();
      if (distances.containsKey(prev)) {
        int dPrev = distances.get(prev);
        myNonTreeEdges.putValue(prev, new GraphEdge<Node>(prev, node, d - dPrev));
        continue;
      }
      distances.put(prev, d);
      myNextNodes.put(prev, node);
      nodes.addLast(prev);
    }
  }
}
 
Example 6
Source File: DFSTBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Comparator<Node> comparator() {
  if (myComparator == null) {
    final TObjectIntHashMap<Node> map = isAcyclic() ? myNodeToNNumber : myNodeToTNumber;
    myComparator = new Comparator<Node>() {
      @Override
      public int compare(@Nonnull Node t, @Nonnull Node t1) {
        return map.get(t) - map.get(t1);
      }
    };
  }
  return myComparator;
}
 
Example 7
Source File: VarModality.java    From openccg with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns a hash code using the given map from vars to ints.
 */
public int hashCode(TObjectIntHashMap varMap) {
	// see if this already in map
	if (varMap.containsKey(this))
		return varMap.get(this);
	// otherwise add it
	int next = varMap.size() + 1;
	varMap.put(this, next);
	return next;
}
 
Example 8
Source File: VarModality.java    From openccg with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
* Returns whether this var equals the given object up to variable names,
* using the given maps from vars to ints.
*/
  public boolean equals(Object obj, TObjectIntHashMap varMap, TObjectIntHashMap varMap2) {
      if (this == obj) return true;
      if (obj.getClass() != this.getClass()) { return false; }
      VarModality vm = (VarModality) obj;
      if (varMap.get(this) != varMap2.get(vm)) return false;
      return true;
  }
 
Example 9
Source File: GFeatVar.java    From openccg with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns a hash code using the given map from vars to ints.
 */
public int hashCode(TObjectIntHashMap varMap) {
	// see if this already in map
	if (varMap.containsKey(this))
		return varMap.get(this);
	// otherwise add it
	int next = varMap.size() + 1;
	varMap.put(this, next);
	return next;
}
 
Example 10
Source File: GFeatVar.java    From openccg with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
* Returns whether this var equals the given object up to variable names,
* using the given maps from vars to ints.
* (Note that the name and index may differ, but the types must be equal.)
*/
  public boolean equals(Object obj, TObjectIntHashMap varMap, TObjectIntHashMap varMap2) {
      if (this == obj) return true;
      if (obj.getClass() != this.getClass()) { return false; }
      GFeatVar gv = (GFeatVar) obj;
      if (varMap.get(this) != varMap2.get(gv)) return false;
      if (!this.type.equals(gv.type)) return false;
      return true;
  }
 
Example 11
Source File: OfflineViewParseUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static Map<String, Set<OfflineProblemDescriptor>> parse(VirtualFile file) {
  final TObjectIntHashMap<String> fqName2IdxMap = new TObjectIntHashMap<>();
  final Map<String, Set<OfflineProblemDescriptor>> package2Result = new THashMap<>();
  try {
    Element rootElement = JDOMUtil.load(VfsUtil.virtualToIoFile(file));
    for (Element problemElement : rootElement.getChildren()) {
      final OfflineProblemDescriptor descriptor = new OfflineProblemDescriptor();
      boolean added = false;

      for (Element childElement : problemElement.getChildren()) {
        String chilName = childElement.getName();

        switch (chilName) {
          case SmartRefElementPointerImpl.ENTRY_POINT:
            descriptor.setType(childElement.getAttributeValue(SmartRefElementPointerImpl.TYPE_ATTR));
            final String fqName = childElement.getAttributeValue(SmartRefElementPointerImpl.FQNAME_ATTR);
            descriptor.setFQName(fqName);

            if (!fqName2IdxMap.containsKey(fqName)) {
              fqName2IdxMap.put(fqName, 0);
            }
            int idx = fqName2IdxMap.get(fqName);
            descriptor.setProblemIndex(idx);
            fqName2IdxMap.put(fqName, idx + 1);

            final List<String> parentTypes = new ArrayList<>();
            final List<String> parentNames = new ArrayList<>();

            for (Element element : childElement.getChildren()) {
              parentTypes.add(element.getAttributeValue(SmartRefElementPointerImpl.TYPE_ATTR));
              parentNames.add(element.getAttributeValue(SmartRefElementPointerImpl.FQNAME_ATTR));
            }

            if (!parentTypes.isEmpty() && !parentNames.isEmpty()) {
              descriptor.setParentType(ArrayUtil.toStringArray(parentTypes));
              descriptor.setParentFQName(ArrayUtil.toStringArray(parentNames));
            }
            break;
          case DESCRIPTION:
            descriptor.setDescription(childElement.getText());
            break;
          case LINE:
            descriptor.setLine(Integer.parseInt(childElement.getText()));
            break;
          case MODULE:
            descriptor.setModule(childElement.getText());
            break;
          case HINTS:
            for (Element hintElement : childElement.getChildren()) {
              List<String> hints = descriptor.getHints();
              if (hints == null) {
                hints = new ArrayList<>();
                descriptor.setHints(hints);
              }
              hints.add(hintElement.getAttributeValue("value"));
            }
            break;
          case PACKAGE:
            appendDescriptor(package2Result, childElement.getText(), descriptor);
            added = true;
            break;
          default:
            for (Element nextElement : childElement.getChildren()) {
              if (PACKAGE.equals(nextElement.getName())) {
                appendDescriptor(package2Result, nextElement.getText(), descriptor);
                added = true;
              }
            }
            break;
        }
      }

      if (!added) appendDescriptor(package2Result, "", descriptor);
    }
  }
  catch (Exception e) {
    LOGGER.error(e);
  }
  return package2Result;
}
 
Example 12
Source File: ControlDependencies.java    From whyline with MIT License 2 votes vote down vote up
private Instruction[] determinePostDominanceFrontiers(TObjectIntHashMap<Instruction> postOrderNumbers, ArrayList<Instruction> instructionsInPostOrderTraversalOfReverseControlFlowGraph) {
			
	// Initialize the dominance array, with null represents the end node of the control flow graph.
	Instruction[] immediatePostDominators = new Instruction[code.getNumberOfInstructions()];

	// Keep an array tracking with instructions have post dominators set. We need this because
	// "null" represents "end node" and not "undefined" in the immediate post dominators array.
	// All of this is because we don't have an end node to point to.
	final boolean[] postDominatorIsSet = new boolean[code.getNumberOfInstructions()];

	boolean changed = true;
	while(changed) {
	
		changed = false;
		for(Instruction currentInstruction : instructionsInPostOrderTraversalOfReverseControlFlowGraph) {
		
			Set<Instruction> successors = currentInstruction.getOrderedSuccessors();
			
			// If this has no successor, then we still mark it as set so that it can be chosen as a post dominator.
			// All of this yuckiness is because we don't have an end node!
			if(successors.isEmpty()) {
				
				postDominatorIsSet[currentInstruction.getIndex()] = true;
				
			}
			else {
				
				// Pick a successor to start with, and then search for other successors that are a better choice.
				Iterator<Instruction> succIterator = successors.iterator();
				Instruction newImmediatePostDominator = succIterator.next();
				
				while(succIterator.hasNext()) {
					
					Instruction successor = succIterator.next();
					// As long as we've assigned an immediate post dominator for this successor, intersect the successor and the current selection for post dominator
					// The trick here is that null could also mean "end node" and not "undefined".
					if(postDominatorIsSet[successor.getIndex()]) {
						
						Instruction finger1 = successor;
						Instruction finger2 = newImmediatePostDominator;

						while(finger1 != null && finger2 != null && finger1 != finger2) {

							while(finger1 != null && finger2 != null && postOrderNumbers.get(finger1) < postOrderNumbers.get(finger2))
								finger1 = immediatePostDominators[finger1.getIndex()];

							while(finger1 != null && finger2 != null && postOrderNumbers.get(finger2) < postOrderNumbers.get(finger1))
								finger2 = immediatePostDominators[finger2.getIndex()];

						}
					
						newImmediatePostDominator = finger1;
						
					}

				}
					
				if(immediatePostDominators[currentInstruction.getIndex()] != newImmediatePostDominator) {

					immediatePostDominators[currentInstruction.getIndex()] = newImmediatePostDominator;
					postDominatorIsSet[currentInstruction.getIndex()] = true;
					changed = true;
					
				}
				
			}
			
		}
					
	}
	
	return immediatePostDominators;
			
}