Ejemplo n.º 1
0
  public static List<Map<String, String>> getSimilarityByList(
      List<Map<String, String>> listMaps, String _qc, String _fq, String file_Id) throws Exception {

    List<Map<String, String>> _list = new ArrayList<Map<String, String>>();

    Similarity similar = new Similarity();
    String svrURL = "http://slc00yek.us.oracle.com:7011/solr-4.1.0/sc_full/select";
    for (Map<String, String> map : listMaps) {
      String _orig = escape(map.get("svalue"));
      List<Map<String, String>> rcdStr = null;
      if (_qc == null)
        rcdStr =
            getValues(
                svrURL,
                _orig + "\"" + _orig + "\"~10 OR ORIGINAL:\"" + _orig + "\"",
                file_Id,
                1,
                _fq,
                map.get("skey"),
                null);
      else
        rcdStr =
            getValues(
                svrURL,
                _orig + "\"" + _orig + "\"~10 OR ORIGINAL:\"" + _orig + "\"" + _qc,
                file_Id,
                1,
                _fq,
                map.get("skey"),
                null);
      if (rcdStr == null || rcdStr.size() == 0) {
        map.put("tvalue", "");
        map.put("similarity", "0");
        _list.add(map);
        continue;
      }
      double sim = -1;
      int idx = 0;
      for (int i = 0; i < rcdStr.size(); i++) {
        double s = similar.Sim(map.get("svalue"), rcdStr.get(i).get("tvalue"));
        if (s > sim) {
          sim = s;
          idx = i;
        }
      }

      map.put("tvalue", rcdStr.get(idx).get("tvalue"));
      map.put("similarity", String.valueOf(sim));
      // map.put("vkey", rcdStr.get(idx).get("vkey"));
      map.put("filepath", rcdStr.get(idx).get("filepath"));
      rcdStr.clear();
      _list.add(map);
    }
    return _list;
  }
Ejemplo n.º 2
0
  private static List<Map<String, String>> readSimpleVerifyValues(
      String urlXml, String skey, String _orig) {

    InputStream isXml = null;
    try {
      URL url = new URL(urlXml);
      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.connect();
      isXml = conn.getInputStream();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      isXml = null;
    }

    if (isXml == null) {
      return null;
    }

    List<Map<String, String>> rcdStr = new LinkedList<Map<String, String>>();
    Document document;
    boolean validating = false;
    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setValidating(validating);
      DocumentBuilder builder = factory.newDocumentBuilder();

      document = builder.parse(isXml);
      document.getDocumentElement().normalize();
      NodeList list = document.getElementsByTagName("doc");
      String _filepath = null, _newval = null, _rn, _dn, _cn, _pn;
      StringBuffer _buffer = new StringBuffer();
      int _cnt = 0, _p100 = 0;
      int cnt = zhuan1.length;
      for (int i = 0; i < list.getLength(); i++) {
        // _buffer.delete(0, _buffer.length());
        Node nodeItem = list.item(i);
        NodeList cldList = nodeItem.getChildNodes();
        Map<String, String> itemContent = new HashMap<String, String>();

        for (int j = 0; j < cldList.getLength(); j++) {
          Node cldItem = cldList.item(j);
          Node nodeAtr = cldItem.getAttributes().getNamedItem("name");
          if (nodeAtr == null) {
            continue;
          }

          String atrValue = nodeAtr.getNodeValue().toUpperCase();
          if (skey != null && atrValue.equals("KEY")) {
            _filepath = cldItem.getTextContent();
            if (_filepath.equals(skey)) {
              itemContent.clear();
              itemContent = null;
              break;
            }
          }
          // String contText = cldItem.getTextContent();
          // if (atrValue.equals("FILE_ID")) {
          // itemContent.put("fileId", contText);
          // } else if (atrValue.equals("KEY")) {
          // itemContent.put("key", contText);
          // } else if (atrValue.equals("VALUE")) {
          // itemContent.put("value", contText);
          // }
          int _idx;
          if (atrValue.equals("FILE_PATH")) {
            _filepath = cldItem.getTextContent();
            // System.out.println(_filepath);
            itemContent.put("filepath", _filepath);
          } else if (atrValue.equals("VALUE")) {
            _newval = cldItem.getTextContent();

            for (int ii = 0; ii < cnt; ii++) {
              _newval = _newval.replace(zhuan1[ii], zhuan2[ii]);
            }
            itemContent.put("tvalue", _newval);
          } else if (atrValue.equals("FID")) {
            _dn = cldItem.getTextContent();
            itemContent.put("fid", _dn);
          }
        }
        // itemContent.put("value", _newval);
        // itemContent.put("filepath", _filepath);

        if (itemContent != null) {
          double _sim2 = similar.Sim(_orig, itemContent.get("tvalue"));
          itemContent.put("sim", String.valueOf(_sim2));
          if (_sim2 >= 1) {
            rcdStr.add(_p100++, itemContent);
            _cnt++;
            continue;
          }

          if (_cnt == 0) rcdStr.add(itemContent);
          else {
            int _idx = _cnt - 1;
            while (_idx >= _p100) {
              Map<String, String> _last = rcdStr.get(_idx);
              double _sim1 = Double.parseDouble(_last.get("sim"));

              if (_sim1 >= _sim2) {
                break;
              }
              _idx--;
            }
            if (_idx == _cnt - 1) rcdStr.add(itemContent);
            else rcdStr.add(_idx + 1, itemContent);
          }
          _cnt++;
        }
      }
    } catch (Exception exp) {
      exp.printStackTrace();
      return null;
    }

    return rcdStr;
  }