Beispiel #1
0
  /**
   * Compute the Information contents of the vertices specified in the given stack.
   *
   * @param allDescendantsInc a map containing the set of inclusive descendants for all the vertices
   *     contained in the graph. The information content will be computed for each vertices
   *     composing the stack considering the number of vertices in the graph equaling the number of
   *     vertices in the stack. Note that the number of descendant is considered to be inclusive
   *     i.e. the count of descendants of a concepts x must also count x.
   * @return a result stack storing the information for each concepts specified in the result stack
   *     specified in parameter.
   * @throws SLIB_Ex_Critic
   */
  public Map<URI, Double> compute(Map<URI, Set<URI>> allDescendantsInc) throws SLIB_Ex_Critic {

    Map<URI, Double> results = new HashMap<URI, Double>();

    double x, cur_ic, nbDesc;

    double setSize = allDescendantsInc.size(); // i.e. number of concepts in the processed graph

    for (URI v : allDescendantsInc.keySet()) {

      nbDesc = allDescendantsInc.get(v).size();

      try {
        cur_ic = computeIC(nbDesc, setSize);
      } catch (SLIB_Ex_Critic e) {
        throw new SLIB_Ex_Critic("Error computing IC of concept " + v + "\n" + e.getMessage());
      }

      results.put(v, cur_ic);
    }

    return results;
  }
Beispiel #2
0
  @Override
  public void populate(GDataConf conf, G g) throws SLIB_Exception {

    this.graph = g;

    default_namespace = (String) conf.getParameter(ARG_PREFIX);

    if (default_namespace == null) {
      default_namespace = graph.getURI().getNamespace();
    }
    try {
      logger.info("-------------------------------------");
      logger.info("Loading Mesh XML");
      logger.info("-------------------------------------");

      idToConcepts = new HashMap<String, MeshConcept>();

      SAXParserFactory parserfactory = SAXParserFactory.newInstance();
      SAXParser saxParser;

      saxParser = parserfactory.newSAXParser();
      saxParser.parse(conf.getLoc(), new MeshXMLHandler(this));

      logger.info(
          "Number of descriptor loaded " + concepts.size() + " (ignored " + conceptIgnored + ")");
      logger.info("Loading relationships ");

      // Create universal root if required
      URI universalRoot = OWL.THING;

      if (!graph.containsVertex(universalRoot)) {
        graph.addV(universalRoot);
      }

      // create relationships and roots of each tree
      for (Entry<String, MeshConcept> e : idToConcepts.entrySet()) {

        MeshConcept c = e.getValue();

        URI vConcept = getOrCreateVertex(c.descriptorUI);

        for (String treeNumber : c.treeNumberList) {

          String parentId = getParentId(treeNumber);

          if (parentId != null) {

            MeshConcept parent = idToConcepts.get(parentId);

            if (parent == null) {
              throw new SLIB_Ex_Critic(
                  "Cannot locate parent identified by TreeNumber "
                      + treeNumber
                      + "\nError occured processing\n"
                      + c);
            } else {

              // System.out.println("\t" + parentId + "\t" + parent.descriptorUI);
              URI vParent = getOrCreateVertex(parent.descriptorUI);
              E edge = new Edge(vConcept, RDFS.SUBCLASSOF, vParent);

              g.addE(edge);
            }
          } else {
            /* Those vertices are the inner roots of each trees,
             * i.e. Psychiatry and Psychology [F] tree has for inner roots:
             *  - Behavior and Behavior Mechanisms [F01]
             *  - Psychological Phenomena and Processes [F02]
             *  - Mental Disorders [F03]
             *  - Behavioral Disciplines and Activities [F04]
             * A vertex has already been created for each inner root (e.g. F01, F02, F03, F04)
             * , we therefore create a vertex for the tree root (e.g. F).
             * Finally all the tree roots are rooted by a global root which do not
             * correspond to a concept specified into the mesh.
             *
             * More information about MeSH trees at http://www.nlm.nih.gov/mesh/trees.html
             */

            // we link the tree inner root to the root tree
            char localNameTreeRoot = treeNumber.charAt(0); // id of the tree root
            URI rootTree = getOrCreateVertex(localNameTreeRoot + ""); // e.g. F
            E treeInnerRootToTreeRoot = new Edge(vConcept, RDFS.SUBCLASSOF, rootTree);
            g.addE(treeInnerRootToTreeRoot);
            //                        logger.debug("Creating Edge : " + treeInnerRootToTreeRoot);

            // we link the tree root to the universal root
            E treeRootToUniversalRoot = new Edge(rootTree, RDFS.SUBCLASSOF, universalRoot);
            g.addE(treeRootToUniversalRoot);
            //                        logger.debug("Creating Edge : " + treeRootToUniversalRoot);
          }
        }
      }

    } catch (IOException ex) {
      throw new SLIB_Ex_Critic(ex.getMessage());
    } catch (ParserConfigurationException ex) {
      throw new SLIB_Ex_Critic(ex.getMessage());
    } catch (SAXException ex) {
      throw new SLIB_Ex_Critic(ex.getMessage());
    } catch (SLIB_Ex_Critic ex) {
      throw new SLIB_Ex_Critic(ex.getMessage());
    }

    logger.info("MESH loader - process performed");
    logger.info("-------------------------------------");
  }