org.apache.commons.collections4.bidimap.DualHashBidiMap Java Examples

The following examples show how to use org.apache.commons.collections4.bidimap.DualHashBidiMap. 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: InteractionAnalysisDetermineDirection.java    From systemsgenetics with GNU General Public License v3.0 6 votes vote down vote up
private static BidiMap<String, String> loadGte(String gtePath) throws IOException {

		BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(gtePath), "UTF-8"));

		String line;

		BidiMap<String, String> gte = new DualHashBidiMap<String, String>();

		while ((line = reader.readLine()) != null) {
			String[] elements = StringUtils.split(line, '\t');
			if (elements.length != 2) {
				throw new RuntimeException("Error in GTE file line: " + line);
			}
			gte.put(elements[0], elements[1]);
		}

		return gte;
	}
 
Example #2
Source File: Users.java    From talent-aio with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 解除绑定
 *
 * @param channelContext the channel context
 */
public void unbind(ChannelContext<SessionContext, P, R> channelContext)
{
	Lock lock = map.getLock().writeLock();
	DualHashBidiMap<String, ChannelContext<SessionContext, P, R>> m = map.getObj();
	try
	{
		lock.lock();
		m.removeValue(channelContext);
	} catch (Exception e)
	{
		throw e;
	} finally
	{
		lock.unlock();
	}
}
 
Example #3
Source File: Users.java    From talent-aio with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 解除绑定
 *
 * @param userid the userid
 * @author: tanyaowu
 * @创建时间: 2016年11月17日 下午2:43:28
 */
public void unbind(String userid)
{
	Lock lock = map.getLock().writeLock();
	DualHashBidiMap<String, ChannelContext<SessionContext, P, R>> m = map.getObj();
	try
	{
		lock.lock();
		m.remove(userid);
	} catch (Exception e)
	{
		throw e;
	} finally
	{
		lock.unlock();
	}
}
 
Example #4
Source File: Users.java    From talent-aio with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 绑定userid.
 *
 * @param userid the userid
 * @param channelContext the channel context
 * @author: tanyaowu
 * @创建时间: 2016年11月17日 下午2:25:46
 */
public void bind(String userid, ChannelContext<SessionContext, P, R> channelContext)
{
	String key = userid;
	Lock lock = map.getLock().writeLock();
	DualHashBidiMap<String, ChannelContext<SessionContext, P, R>> m = map.getObj();

	try
	{
		lock.lock();
		m.put(key, channelContext);
		channelContext.setUserid(userid);
	} catch (Exception e)
	{
		throw e;
	} finally
	{
		lock.unlock();
	}
}
 
Example #5
Source File: Users.java    From talent-aio with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Find.
 *
 * @param userid the userid
 * @return the channel context
 */
public ChannelContext<SessionContext, P, R> find(String userid)
{
	String key = userid;
	Lock lock = map.getLock().readLock();
	DualHashBidiMap<String, ChannelContext<SessionContext, P, R>> m = map.getObj();

	try
	{
		lock.lock();
		return (ChannelContext<SessionContext, P, R>) m.get(key);
	} catch (Exception e)
	{
		throw e;
	} finally
	{
		lock.unlock();
	}
}
 
Example #6
Source File: ClientNodes.java    From talent-aio with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Removes映射
 *
 * @param <Ext> the generic type
 * @param <P> the generic type
 * @param <R> the generic type
 * @param channelContext the channel context
 */
public void remove(ChannelContext<SessionContext, P, R> channelContext)
{
	Lock lock = map.getLock().writeLock();
	DualHashBidiMap<String, ChannelContext<SessionContext, P, R>> m = map.getObj();
	try
	{
		lock.lock();
		m.removeValue(channelContext);
	} catch (Exception e)
	{
		throw e;
	} finally
	{
		lock.unlock();
	}
}
 
Example #7
Source File: ClientNodes.java    From talent-aio with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 添加映射.
 *
 * @param <Ext> the generic type
 * @param <P> the generic type
 * @param <R> the generic type
 * @param channelContext the channel context
 * @author: tanyaowu
 * @创建时间: 2016年11月17日 下午2:25:46
 */
public void put(ChannelContext<SessionContext, P, R> channelContext)
{
	String key = getKey(channelContext);
	Lock lock = map.getLock().writeLock();
	DualHashBidiMap<String, ChannelContext<SessionContext, P, R>> m = map.getObj();

	try
	{
		lock.lock();
		m.put(key, channelContext);
	} catch (Exception e)
	{
		throw e;
	} finally
	{
		lock.unlock();
	}
}
 
Example #8
Source File: ClientNodes.java    From talent-aio with GNU Lesser General Public License v2.1 6 votes vote down vote up
public ChannelContext<SessionContext, P, R> find(String key)
{
	Lock lock = map.getLock().readLock();
	DualHashBidiMap<String, ChannelContext<SessionContext, P, R>> m = map.getObj();

	try
	{
		lock.lock();
		return (ChannelContext<SessionContext, P, R>) m.get(key);
	} catch (Exception e)
	{
		throw e;
	} finally
	{
		lock.unlock();
	}
}
 
Example #9
Source File: BidiMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenKeyValue_whenAddValue_thenReplaceFirstKey() {
    BidiMap<String, String> map = new DualHashBidiMap<>();
    map.put("key1", "value1");
    map.put("key2", "value1");
    assertEquals(map.size(), 1);
    assertFalse(map.containsKey("key1"));
}
 
Example #10
Source File: BidiMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenValue_whenRemoveValue_thenRemoveMatchingMapEntry() {
    BidiMap<String, String> map = new DualHashBidiMap<>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.removeValue("value2");
    assertFalse(map.containsKey("key2"));
}
 
Example #11
Source File: BidiMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenInverseBidiMap_thenInverseKeyValue() {
    BidiMap<String, String> map = new DualHashBidiMap<>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    BidiMap<String, String> rMap = map.inverseBidiMap();
    assertTrue(rMap.containsKey("value1") && rMap.containsKey("value2"));
}
 
Example #12
Source File: BidiMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenKeyValue_whenPut_thenAddEntryToMap() {
    BidiMap<String, String> map = new DualHashBidiMap<>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    assertEquals(map.size(), 2);
}
 
Example #13
Source File: PolarityClassifier.java    From sentiment-analysis with Apache License 2.0 5 votes vote down vote up
/**Initializes the BidiMaps.*/
private void initializeAttributes(BidiMap<String, Integer> tb, BidiMap<String, Integer> fb, BidiMap<String, Integer> cb){
	tba = new DualHashBidiMap<String, Integer>();
	fba = new DualHashBidiMap<String, Integer>();
	cba = new DualHashBidiMap<String, Integer>();
	tba = tb;
	fba = fb;
	cba = cb;
}
 
Example #14
Source File: Trainer.java    From sentiment-analysis with Apache License 2.0 5 votes vote down vote up
/**Sets the folder name where the "training" .arff files are located.*/
public Trainer(String f){
	folder = f;
	tba = new DualHashBidiMap<String, Integer>();
	fba = new DualHashBidiMap<String, Integer>();
	cba = new DualHashBidiMap<String, Integer>();
}
 
Example #15
Source File: SentimentAnalyser.java    From sentiment-analysis with Apache License 2.0 5 votes vote down vote up
/**Constructor. 
 * "main_folder" is provided in order to define the initial directory to work on; 
 * "useSW" refers to whether the training should be made on the most recent 1,000 tweets or no.
 * @throws Exception */
public SentimentAnalyser(String main_folder, boolean useSW, String test_dataset) throws Exception{
	tr = new Trainer(main_folder);			//tr.train();
	pc = new PolarityClassifier(main_folder, tr.getTextAttributes(), tr.getFeatureAttributes(), tr.getComplexAttributes());
	tp = new TweetPreprocessor(main_folder);
	initializeFilter();
	
	useSlidingWindow = useSW;
       ArrayList<Attribute> attributes = new ArrayList<Attribute>();
       ArrayList<String> classVal = new ArrayList<String>();
       classVal.add("positive");
       classVal.add("negative");
       attributes.add(new Attribute("text",(ArrayList<String>)null));
       attributes.add(new Attribute("sentimentClassValue",classVal));
	train = new Instances("somerel", attributes, 0);
	train.setClassIndex(1);
	test = new Instances("somerel", attributes, 0);
	test.setClassIndex(1);
	
	if (useSlidingWindow == false){
		multiNB = (Classifier) weka.core.SerializationHelper.read(main_folder+"/test_models/"+test_dataset+".model");
		BufferedReader rd = new BufferedReader(new FileReader(new File(main_folder+"test_models/"+test_dataset+"-attributes.tsv")));
		train_attributes = new DualHashBidiMap<String, Integer>();
		String inline;
		int cnt = 0;
		while ((inline=rd.readLine())!=null){
			train_attributes.put(inline, cnt);
			cnt++;
		}
		rd.close();
		BufferedReader frd = new BufferedReader(new FileReader(new File(main_folder+"test_models/"+test_dataset+"-attributes.arff")));
		training_text = new Instances(frd);
		frd.close();
	}
}
 
Example #16
Source File: ApacheBidiMapTest.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    String[] englishWords = {"one", "two", "three","ball","snow"};
    String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};

    // Создаем Multiset
    BidiMap<String, String> biMap = new DualHashBidiMap();
    // создаем англо-польский словарь
    int i = 0;
    for(String englishWord: englishWords) {
        biMap.put(englishWord, russianWords[i]);
        i++;
    }

    // Выводим кол-вом вхождений слов
    System.out.println(biMap); // напечатает {ball=kula, snow=snieg, one=jeden, two=dwa, three=trzy}- в произвольном порядке
    // Выводим все уникальные слова
    System.out.println(biMap.keySet());    // напечатает [ball, snow, one, two, three]- в произвольном порядке
    System.out.println(biMap.values());    // напечатает [kula, snieg, jeden, dwa, trzy]- в произвольном порядке

    // Выводим перевод по каждому слову
    System.out.println("one = " + biMap.get("one"));    // напечатает one = jeden
    System.out.println("two = " + biMap.get("two"));    // напечатает two = dwa
    System.out.println("kula = " + biMap.getKey("kula"));    // напечатает kula = ball
    System.out.println("snieg = " + biMap.getKey("snieg"));    // напечатает snieg = snow
    System.out.println("empty = " + biMap.get("empty"));    // напечатает empty = null

    // Выводим общее количество переводов в словаре
    System.out.println(biMap.size());    //напечатает 5

}
 
Example #17
Source File: ApacheBidiMapTest.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    String[] englishWords = {"one", "two", "three","ball","snow"};
    String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};

    // Create Multiset
    BidiMap<String, String> biMap = new DualHashBidiMap();
    // Create Polish-English dictionary
    int i = 0;
    for(String englishWord: englishWords) {
        biMap.put(englishWord, russianWords[i]);
        i++;
    }

    // Print count words
    System.out.println(biMap); // Print "{ball=kula, snow=snieg, one=jeden, two=dwa, three=trzy}" - in random orders
    // Print unique words
    System.out.println(biMap.keySet());    // print "[ball, snow, one, two, three]"- in random orders
    System.out.println(biMap.values());    // print "[kula, snieg, jeden, dwa, trzy]" - in random orders

    // Print translate by words
    System.out.println("one = " + biMap.get("one"));    // print one = jeden
    System.out.println("two = " + biMap.get("two"));    // print two = dwa
    System.out.println("kula = " + biMap.getKey("kula"));    // print kula = ball
    System.out.println("snieg = " + biMap.getKey("snieg"));    // print snieg = snow
    System.out.println("empty = " + biMap.get("empty"));    // print empty = null

    // Print count word's pair
    System.out.println(biMap.size());    //print 5

}
 
Example #18
Source File: JRCsvDataSource.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void assignColumnNames()
{
	BidiMap<Integer, String> indexColumns = new DualHashBidiMap<Integer, String>();
	for (int i = 0; i < crtRecordColumnValues.size(); i++)
	{
		String name = crtRecordColumnValues.get(i);
		
		Integer existingIdx = indexColumns.getKey(name);
		if (existingIdx == null)
		{
			//use the name from the file if possible
			indexColumns.put(i, name);
		}
		else
		{
			//the name is taken, force COLUMN_i for this column and recursively if COLUMN_x is already used
			Integer forceIndex = i;
			do
			{
				String indexName = INDEXED_COLUMN_PREFIX + forceIndex;
				Integer existingIndex = indexColumns.getKey(indexName);
				indexColumns.put(forceIndex, indexName);
				forceIndex = existingIndex;
			}
			while(forceIndex != null);
		}
	}
	
	this.columnNames = new LinkedHashMap<String, Integer>();
	for (int i = 0; i < crtRecordColumnValues.size(); i++)
	{
		String columnName = indexColumns.get(i);
		this.columnNames.put(columnName, i);
	}
}
 
Example #19
Source File: MapUtilUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenUsingBidiMap_shouldReturnKey() {
    BidiMap<String, String> capitalCountryMap = new DualHashBidiMap<String, String>();
    capitalCountryMap.put("Berlin", "Germany");
    capitalCountryMap.put("Cape Town", "South Africa");
    assertEquals("Berlin", capitalCountryMap.getKey("Germany"));
}
 
Example #20
Source File: Users.java    From talent-aio with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * The main method.
 *
 * @param args the arguments
 * @author: tanyaowu
 * @创建时间: 2016年11月17日 下午1:12:56
 */
public static void main(String[] args)
{
	DualHashBidiMap<String, String> dualHashBidiMap = new DualHashBidiMap<>();
	dualHashBidiMap.put("111", "111111");
	dualHashBidiMap.put("222", "111111");
	System.out.println(dualHashBidiMap.getKey("111111"));
}
 
Example #21
Source File: MapUtilUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenUsingBidiMapAddDuplicateValue_shouldRemoveOldEntry() {
    BidiMap<String, String> capitalCountryMap = new DualHashBidiMap<String, String>();
    capitalCountryMap.put("Berlin", "Germany");
    capitalCountryMap.put("Cape Town", "South Africa");
    capitalCountryMap.put("Pretoria", "South Africa");
    assertEquals("Pretoria", capitalCountryMap.getKey("South Africa"));
}
 
Example #22
Source File: FunctionGraphFactory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private static BidiMap<CodeBlock, FGVertex> createVertices(Function function,
		final FGController controller, TaskMonitor monitor) throws CancelledException {

	BidiMap<CodeBlock, FGVertex> vertices = new DualHashBidiMap<>();
	CodeBlockModel blockModel = new BasicBlockModel(controller.getProgram());

	AddressSetView addresses = function.getBody();
	CodeBlockIterator iterator = blockModel.getCodeBlocksContaining(addresses, monitor);
	monitor.initialize(addresses.getNumAddresses());

	for (; iterator.hasNext();) {
		CodeBlock codeBlock = iterator.next();

		FlowType flowType = codeBlock.getFlowType();
		boolean isEntry = isEntry(codeBlock);
		Address cbStart = codeBlock.getFirstStartAddress();
		if (cbStart.equals(function.getEntryPoint())) {
			isEntry = true;
		}

		FGVertex vertex =
			new ListingFunctionGraphVertex(controller, codeBlock, flowType, isEntry);
		vertices.put(codeBlock, vertex);

		long blockAddressCount = codeBlock.getNumAddresses();
		long currentProgress = monitor.getProgress();
		monitor.setProgress(currentProgress + blockAddressCount);
	}

	return vertices;
}
 
Example #23
Source File: DagInfo.java    From tez with Apache License 2.0 4 votes vote down vote up
DagInfo(JSONObject jsonObject) throws JSONException {
  super(jsonObject);

  vertexNameMap = Maps.newHashMap();
  vertexNameIDMapping = new DualHashBidiMap<>();
  edgeInfoMap = Maps.newHashMap();
  basicVertexInfoMap = Maps.newHashMap();
  containerMapping = LinkedHashMultimap.create();

  Preconditions.checkArgument(jsonObject.getString(Constants.ENTITY_TYPE).equalsIgnoreCase
      (Constants.TEZ_DAG_ID));

  dagId = StringInterner.weakIntern(jsonObject.getString(Constants.ENTITY));

  //Parse additional Info
  JSONObject otherInfoNode = jsonObject.getJSONObject(Constants.OTHER_INFO);

  long sTime = otherInfoNode.optLong(Constants.START_TIME);
  long eTime= otherInfoNode.optLong(Constants.FINISH_TIME);
  userName = otherInfoNode.optString(Constants.USER);
  if (eTime < sTime) {
    LOG.warn("DAG has got wrong start/end values. "
        + "startTime=" + sTime + ", endTime=" + eTime + ". Will check "
        + "timestamps in DAG started/finished events");

    // Check if events DAG_STARTED, DAG_FINISHED can be made use of
    for(Event event : eventList) {
      switch (HistoryEventType.valueOf(event.getType())) {
      case DAG_STARTED:
        sTime = event.getAbsoluteTime();
        break;
      case DAG_FINISHED:
        eTime = event.getAbsoluteTime();
        break;
      default:
        break;
      }
    }

    if (eTime < sTime) {
      LOG.warn("DAG has got wrong start/end values in events as well. "
          + "startTime=" + sTime + ", endTime=" + eTime);
    }
  }
  startTime = sTime;
  endTime = eTime;

  //TODO: Not getting populated correctly for lots of jobs.  Verify
  submitTime = otherInfoNode.optLong(Constants.START_REQUESTED_TIME);
  diagnostics = otherInfoNode.optString(Constants.DIAGNOSTICS);
  failedTasks = otherInfoNode.optInt(Constants.NUM_FAILED_TASKS);
  JSONObject dagPlan = otherInfoNode.optJSONObject(Constants.DAG_PLAN);
  name = StringInterner.weakIntern((dagPlan != null) ? (dagPlan.optString(Constants.DAG_NAME)) : null);
  if (dagPlan != null) {
    JSONArray vertices = dagPlan.optJSONArray(Constants.VERTICES);
    if (vertices != null) {
      numVertices = vertices.length();
    } else {
      numVertices = 0;
    }
    parseDAGPlan(dagPlan);
  } else {
    numVertices = 0;
  }
  status = StringInterner.weakIntern(otherInfoNode.optString(Constants.STATUS));

  //parse name id mapping
  JSONObject vertexIDMappingJson = otherInfoNode.optJSONObject(Constants.VERTEX_NAME_ID_MAPPING);
  if (vertexIDMappingJson != null) {
    //get vertex name
    for (Map.Entry<String, BasicVertexInfo> entry : basicVertexInfoMap.entrySet()) {
      String vertexId = vertexIDMappingJson.optString(entry.getKey());
      //vertexName --> vertexId
      vertexNameIDMapping.put(entry.getKey(), vertexId);
    }
  }
}
 
Example #24
Source File: BidiMapUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void givenValue_whenGetKey_thenMappedKey() {
    BidiMap<String, String> map = new DualHashBidiMap<>();
    map.put("key1", "value1");
    assertEquals(map.getKey("value1"), "key1");
}
 
Example #25
Source File: ClientNodes.java    From talent-aio with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * @return the map
 */
public ObjWithLock<DualHashBidiMap<String, ChannelContext<SessionContext, P, R>>> getMap()
{
	return map;
}
 
Example #26
Source File: Users.java    From talent-aio with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * @return the map
 */
public ObjWithLock<DualHashBidiMap<String, ChannelContext<SessionContext, P, R>>> getMap()
{
	return map;
}
 
Example #27
Source File: DefaultXapiToCaliperConversionService.java    From OpenLRW with Educational Community License v2.0 4 votes vote down vote up
@PostConstruct
private void init() {
  verbActionMap = new DualHashBidiMap<>();
  verbActionMap.put(Action.ABANDONED, "https://w3id.org/xapi/adl/verbs/abandoned");
  verbActionMap.put(Action.ATTACHED, "http://activitystrea.ms/schema/1.0/attach");    
  verbActionMap.put(Action.BOOKMARKED, "http://id.tincanapi.com/verb/bookmarked");
  verbActionMap.put(Action.COMMENTED, "http://adlnet.gov/expapi/verbs/commented");
  verbActionMap.put(Action.COMPLETED, "http://adlnet.gov/expapi/verbs/completed");
  verbActionMap.put(Action.DISLIKED, "http://activitystrea.ms/schema/1.0/dislike");
  verbActionMap.put(Action.GRADED, "http://adlnet.gov/expapi/verbs/scored");
  verbActionMap.put(Action.LIKED, "http://activitystrea.ms/schema/1.0/like");
  verbActionMap.put(Action.LOGGED_IN, "https://brindlewaye.com/xAPITerms/verbs/loggedin/");
  verbActionMap.put(Action.LOGGED_OUT, "https://brindlewaye.com/xAPITerms/verbs/loggedout/");
  verbActionMap.put(Action.PAUSED, "http://id.tincanapi.com/verb/paused");
  verbActionMap.put(Action.QUESTIONED, "http://adlnet.gov/expapi/verbs/asked");
  verbActionMap.put(Action.REPLIED, "http://adlnet.gov/expapi/verbs/responded");
  verbActionMap.put(Action.RESUMED, "http://adlnet.gov/expapi/verbs/resumed");
  verbActionMap.put(Action.REVIEWED, "http://id.tincanapi.com/verb/reviewed");
  verbActionMap.put(Action.SEARCHED, "http://activitystrea.ms/schema/1.0/search");
  verbActionMap.put(Action.SHARED, "http://activitystrea.ms/schema/1.0/share");
  verbActionMap.put(Action.SKIPPED, "http://id.tincanapi.com/verb/skipped");
  verbActionMap.put(Action.STARTED, "http://activitystrea.ms/schema/1.0/start");
  verbActionMap.put(Action.SUBMITTED, "http://activitystrea.ms/schema/1.0/submit");
  verbActionMap.put(Action.TAGGED, "http://activitystrea.ms/schema/1.0/tag");
  verbActionMap.put(Action.VIEWED, "http://id.tincanapi.com/verb/viewed");
  
  objectEntityMap = new DualHashBidiMap<>();
  // ToDo support other xapi annotation types
  objectEntityMap.put(EntityType.ANNOTATION, "http://risc-inc.com/annotator/activities/highlight");
  objectEntityMap.put(EntityType.COURSE_SECTION, "http://adlnet.gov/expapi/activities/course");
  objectEntityMap.put(EntityType.DIGITAL_RESOURCE, "http://adlnet.gov/expapi/activities/media");
  objectEntityMap.put(EntityType.GROUP, "http://activitystrea.ms/schema/1.0/group");
  objectEntityMap.put(EntityType.LEARNING_OBJECTIVE, "http://adlnet.gov/expapi/activities/objective");
  objectEntityMap.put(EntityType.PERSON, "http://activitystrea.ms/schema/1.0/person");
  objectEntityMap.put(EntityType.ORGANIZATION, "http://activitystrea.ms/schema/1.0/organization");
  objectEntityMap.put(EntityType.SOFTWARE_APPLICATION, "http://activitystrea.ms/schema/1.0/application");
  objectEntityMap.put(DigitalResourceType.MEDIA_OBJECT, "http://adlnet.gov/expapi/activities/media");
  objectEntityMap.put(DigitalResourceType.WEB_PAGE, "http://activitystrea.ms/schema/1.0/page");
  
  actionEventMap = new HashMap<>();
  actionEventMap.put(Action.ABANDONED, EventType.ASSIGNABLE);
  actionEventMap.put(Action.ACTIVATED, EventType.ASSIGNABLE);
  actionEventMap.put(Action.ATTACHED, EventType.ANNOTATION);    
  actionEventMap.put(Action.BOOKMARKED, EventType.ANNOTATION);
  actionEventMap.put(Action.CHANGED_RESOLUTION, EventType.MEDIA);
  actionEventMap.put(Action.CHANGED_SIZE, EventType.MEDIA);
  actionEventMap.put(Action.CHANGED_VOLUME, EventType.MEDIA);
  actionEventMap.put(Action.CLASSIFIED, EventType.ANNOTATION);
  actionEventMap.put(Action.CLOSED_POPOUT, EventType.MEDIA);
  actionEventMap.put(Action.COMMENTED, EventType.ANNOTATION);
  actionEventMap.put(Action.COMPLETED, EventType.ASSIGNABLE);
  actionEventMap.put(Action.DEACTIVATED, EventType.ASSIGNABLE);
  actionEventMap.put(Action.DESCRIBED, EventType.ANNOTATION);
  actionEventMap.put(Action.DISLIKED, EventType.ANNOTATION);
  actionEventMap.put(Action.DISABLED_CLOSED_CAPTIONING, EventType.MEDIA);
  actionEventMap.put(Action.ENABLED_CLOSED_CAPTIONING, EventType.MEDIA);
  actionEventMap.put(Action.ENDED, EventType.MEDIA);
  actionEventMap.put(Action.ENTERED_FULLSCREEN, EventType.MEDIA);
  actionEventMap.put(Action.EXITED_FULLSCREEN, EventType.MEDIA);
  actionEventMap.put(Action.FORWARDED_TO, EventType.MEDIA);
  actionEventMap.put(Action.GRADED, EventType.OUTCOME);
  actionEventMap.put(Action.HID, EventType.ASSIGNABLE);
  actionEventMap.put(Action.HIGHLIGHTED, EventType.ANNOTATION);
  actionEventMap.put(Action.JUMPED_TO, EventType.MEDIA);
  actionEventMap.put(Action.IDENTIFIED, EventType.ANNOTATION);
  actionEventMap.put(Action.LIKED, EventType.ANNOTATION);
  actionEventMap.put(Action.LINKED, EventType.ANNOTATION);
  actionEventMap.put(Action.LOGGED_IN, EventType.SESSION);
  actionEventMap.put(Action.LOGGED_OUT, EventType.SESSION);   
  actionEventMap.put(Action.MUTED, EventType.MEDIA);
  actionEventMap.put(Action.NAVIGATED_TO, EventType.NAVIGATION);
  actionEventMap.put(Action.OPENED_POPOUT, EventType.MEDIA);
  actionEventMap.put(Action.PAUSED, EventType.MEDIA);
  actionEventMap.put(Action.RANKED, EventType.ANNOTATION);
  actionEventMap.put(Action.QUESTIONED, EventType.ANNOTATION);
  actionEventMap.put(Action.RECOMMENDED, EventType.ANNOTATION);
  actionEventMap.put(Action.REPLIED, EventType.ANNOTATION);
  actionEventMap.put(Action.RESTARTED, EventType.ASSESSMENT);
  actionEventMap.put(Action.RESUMED, EventType.MEDIA);
  actionEventMap.put(Action.REVIEWED, EventType.ASSIGNABLE);
  actionEventMap.put(Action.REWOUND, EventType.MEDIA);
  actionEventMap.put(Action.SEARCHED, EventType.READING);
  actionEventMap.put(Action.SHARED, EventType.ANNOTATION);
  actionEventMap.put(Action.SHOWED, EventType.ASSIGNABLE);
  actionEventMap.put(Action.SKIPPED, EventType.ASSESSMENT_ITEM);
  actionEventMap.put(Action.STARTED, EventType.EVENT);
  actionEventMap.put(Action.SUBMITTED, EventType.EVENT);
  actionEventMap.put(Action.SUBSCRIBED, EventType.ANNOTATION);
  actionEventMap.put(Action.TAGGED, EventType.ANNOTATION);
  actionEventMap.put(Action.TIMED_OUT, EventType.SESSION);
  actionEventMap.put(Action.VIEWED, EventType.EVENT);
  actionEventMap.put(Action.UNMUTED, EventType.MEDIA);

}
 
Example #28
Source File: DecompilerNestedLayout.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private BlockGraph buildCurrentFunctionGraph(Program program,
		VisualGraph<FGVertex, FGEdge> jungGraph, TaskMonitor taskMonitor)
		throws CancelledException {

	CodeBlockModel blockModel = new BasicBlockModel(program);
	AddressSetView addresses = function.getBody();
	CodeBlockIterator iterator = blockModel.getCodeBlocksContaining(addresses, taskMonitor);

	BlockGraph blockGraph = new BlockGraph();
	BidiMap<CodeBlock, PcodeBlock> bidiMap = new DualHashBidiMap<>();
	for (; iterator.hasNext();) {
		taskMonitor.checkCanceled();

		CodeBlock codeBlock = iterator.next();
		FGVertex vertex = getVertex(jungGraph, codeBlock.getMinAddress());
		if (vertex == null) {
			// this is unusual; can happen if the program is being changed while this is running
			continue;
		}

		PcodeBlock pcodeBlock = new BlockCopy(vertex, codeBlock.getMinAddress());
		bidiMap.put(codeBlock, pcodeBlock);
		blockGraph.addBlock(pcodeBlock);
	}

	for (CodeBlock block : bidiMap.keySet()) {
		taskMonitor.checkCanceled();

		CodeBlockReferenceIterator destinations = block.getDestinations(taskMonitor);
		while (destinations.hasNext()) {
			taskMonitor.checkCanceled();

			CodeBlockReference ref = destinations.next();
			// We only want control flow that is internal to the function. Make sure to
			// exclude the case where a function contains a (recursive) call to itself:
			// The reference would be between addresses internal to the function, but the
			// link doesn't represent internal flow. So we filter out ANY call reference.
			if (ref.getFlowType().isCall()) {
				continue;
			}
			CodeBlock destination = ref.getDestinationBlock();

			PcodeBlock sourcePcodeBlock = bidiMap.get(block);
			PcodeBlock destPcodeBlock = bidiMap.get(destination);
			if (destPcodeBlock == null) {
				continue;
			}

			blockGraph.addEdge(sourcePcodeBlock, destPcodeBlock);
		}
	}

	blockGraph.setIndices();
	return blockGraph;
}