示例#1
0
 @Override
 public int compare(SNRSimilarityRecord snr1, SNRSimilarityRecord snr2) {
   if (snr1.getSimilarity() < snr2.getSimilarity()) {
     return 1;
   } else {
     return -1;
   }
 }
示例#2
0
  public static HashMap<SemanticNetRelationship, SemanticNetRelationship> mapSimilarRelationships(
      ArrayList<SNRSimilarityRecord> SNRSList) {
    // Find node with highest similarity value
    HashMap<SemanticNetRelationship, SemanticNetRelationship> pairings =
        new HashMap<SemanticNetRelationship, SemanticNetRelationship>();
    HashMap<SemanticNetRelationship, SNRSimilarityRecord> s_snr_2_snr_sr_map =
        new HashMap<SemanticNetRelationship, SNRSimilarityRecord>();
    HashMap<SemanticNetRelationship, SNRSimilarityRecord> d_snr_2_snr_sr_map =
        new HashMap<SemanticNetRelationship, SNRSimilarityRecord>();
    // HashMap<String, String> S2DMap = new HashMap<String, String>();
    // HashMap<String, String> D2SMap = new HashMap<String, String>();
    // SemanticNetNode maxSimilarityNode = null;

    for (SNRSimilarityRecord snr_sr : SNRSList) {
      // SemanticNetNode sNode = s1.getNodeByName(nsr.getSourceNodeName());
      // SemanticNetNode dNode = s2.getNodeByName(nsr.getDestinationNodeName());
      if (!pairings.containsKey(snr_sr.getSourceSNR())
          && !pairings.containsValue(snr_sr.getDestinationSNR())) {
        pairings.put(snr_sr.getSourceSNR(), snr_sr.getDestinationSNR());
        s_snr_2_snr_sr_map.put(snr_sr.getSourceSNR(), snr_sr);
        d_snr_2_snr_sr_map.put(snr_sr.getDestinationSNR(), snr_sr);
        // S2DMap.put(nsr.getSourceNodeName(), nsr.getDesinationNodeName());
        // D2SMap.put(nsr.getDesinationNodeName(), nsr.getSourceNodeName());
      } else if (pairings.containsKey(
          snr_sr.getSourceSNR())) // risk of redundantly mapping same source node
      {

        // pairings.put(new SemanticNetRelationship("prior"), snr.getDestinationSNR());
        SNRSimilarityRecord prior_snr_sr = s_snr_2_snr_sr_map.get(snr_sr.getSourceSNR());
        // SemanticNetRelationship priorDSNR = pairings.get(snr.getDestinationSNR());
        // SemanticNetRelationship priorSSNR = pairings.get(snr.getSourceSNR());
        // SemanticNetNode priorDNode = s2.getNodeByName(priorNsr.getDestinationNodeName());
        if (snr_sr.similarity > prior_snr_sr.similarity) {
          pairings.remove(prior_snr_sr.getSourceSNR());
          s_snr_2_snr_sr_map.remove(prior_snr_sr.getSourceSNR());
          d_snr_2_snr_sr_map.remove(prior_snr_sr.getDestinationSNR());

          pairings.put(snr_sr.getSourceSNR(), snr_sr.getDestinationSNR());
          s_snr_2_snr_sr_map.put(snr_sr.getSourceSNR(), snr_sr);
          d_snr_2_snr_sr_map.put(snr_sr.getDestinationSNR(), snr_sr);
          /*if(sNSRMap.size() == s1.getNodes().size())
          {
          	pairings.put((, value)
          }*/
        } else if (snr_sr.similarity > prior_snr_sr.similarity) {
          // Log These Cases...
        }

      } else // risk of redundantly mapping same destination node
      {
        // pairings.put( snr.getSourceSNR(), new SemanticNetRelationship("posterior"));

        SNRSimilarityRecord prior_snr_sr = d_snr_2_snr_sr_map.get(snr_sr.getDestinationSNR());
        if (snr_sr.similarity > prior_snr_sr.similarity) {
          pairings.remove(prior_snr_sr.getSourceSNR());
          s_snr_2_snr_sr_map.remove(prior_snr_sr.getSourceSNR());
          d_snr_2_snr_sr_map.remove(prior_snr_sr.getDestinationSNR());

          pairings.put(snr_sr.getSourceSNR(), snr_sr.getDestinationSNR());
          s_snr_2_snr_sr_map.put(snr_sr.getSourceSNR(), snr_sr);
          d_snr_2_snr_sr_map.put(snr_sr.getDestinationSNR(), snr_sr);
        } else if (snr_sr.similarity > prior_snr_sr.similarity) {
          // Log These Cases...
        }
      }
    }
    return pairings;
  }