コード例 #1
0
  /*
   *get collaboration information based on organisation - returns a collaborationList.
   */
  public HashMap<Integer, CollaborationList> getCollaborations_org(
      String id, TreeMap<Integer, Collaborator> network) {
    HashMap<Integer, CollaborationList> collaborations =
        new java.util.HashMap<Integer, CollaborationList>();

    // reset the iterator
    Set<Integer> networkKeys = network.keySet();
    Iterator<Integer> networkKeyIterator = networkKeys.iterator();
    Integer networkKey = null;

    CollaborationList collaborationList;

    // loop through the list of keys
    while (networkKeyIterator.hasNext()) {

      // get the key
      networkKey = (Integer) networkKeyIterator.next();

      // get the list of collaborations for this user
      collaborationList = getCollaborationList_org(id, networkKey.toString());

      // add the collaborationList object to the list
      collaborations.put(networkKey, collaborationList);
    }

    return collaborations;
  }
コード例 #2
0
  /*
   * add some of the additional required information for collaborator
   */
  public ArrayList<Collaborator> getCollaborators(
      TreeMap<Integer, Collaborator> network, String id) {

    // declare helper variables
    java.util.ArrayList<Collaborator> collaborators = new java.util.ArrayList<Collaborator>();

    // define a SPARQL query to get details about a collaborator
    String sparqlQuery =
        "PREFIX foaf:       <"
            + FOAF.NS
            + ">"
            + "PREFIX ausestage:  <"
            + AuseStage.NS
            + "> "
            + "SELECT ?collabName ?function ?gender ?nationality  "
            + "WHERE {  "
            + "       @ a foaf:Person ; "
            + "           foaf:name ?collabName. "
            + "OPTIONAL {@ ausestage:function ?function} "
            + "OPTIONAL {@ foaf:gender ?gender} "
            + "OPTIONAL {@ ausestage:nationality ?nationality} "
            + "} ";

    String queryToExecute = null;

    ResultSet results = null;
    QuerySolution row = null;
    Collaborator collaborator = null;

    // loop through the list of collaborators and get additional information
    Collection networkKeys = network.keySet();
    Iterator networkKeyIterator = networkKeys.iterator();
    Integer networkKey = null;
    Integer centreId = Integer.parseInt(id);

    // loop through the list of keys
    while (networkKeyIterator.hasNext()) {

      // get the key for this collaborator
      networkKey = (Integer) networkKeyIterator.next();

      // create a new collaborator object
      collaborator = new Collaborator(networkKey.toString());

      // build the query
      queryToExecute =
          sparqlQuery.replaceAll(
              "@", "<" + AusStageURI.getContributorURI(collaborator.getId()) + ">");

      // execute the query
      results = rdf.executeSparqlQuery(queryToExecute);

      // add details to this contributor
      while (results.hasNext()) {
        // loop though the resulset
        // get a new row of data
        row = results.nextSolution();

        // add the data to the collaborator
        collaborator.setName(row.get("collabName").toString());
        if (row.get("function") != null) {
          collaborator.setFunction(row.get("function").toString());
        }

        if (row.get("gender") != null) {
          collaborator.setGender(row.get("gender").toString());
        }

        if (row.get("nationality") != null) {
          collaborator.setNationality(row.get("nationality").toString());
        }

        collaborator.setUrl(AusStageURI.getContributorURL(collaborator.getId()));
      }

      // play nice and tidy
      rdf.tidyUp();
      results = null;

      // add the collaborator to the list
      collaborators.add(collaborator);
    }

    return collaborators;
  }