/**
   * Query SPARQL endpoint with a SELECT query
   *
   * @param qExec QueryExecution encapsulating the query
   * @return model retrieved by querying the endpoint
   */
  private Model getSelectModel(QueryExecution qExec) {
    Model model = ModelFactory.createDefaultModel();
    Graph graph = model.getGraph();
    ResultSet results = qExec.execSelect();

    while (results.hasNext()) {
      QuerySolution sol = results.next();
      String subject;
      String predicate;
      RDFNode object;

      try {
        subject = sol.getResource("s").toString();
        predicate = sol.getResource("p").toString();
        object = sol.get("o");
      } catch (NoSuchElementException e) {
        logger.error("SELECT query does not return a (?s ?p ?o) Triple");
        continue;
      }

      Node objNode;
      if (object.isLiteral()) {
        Literal obj = object.asLiteral();
        objNode = NodeFactory.createLiteral(obj.getString(), obj.getDatatype());
      } else {
        objNode = NodeFactory.createLiteral(object.toString());
      }

      graph.add(
          new Triple(NodeFactory.createURI(subject), NodeFactory.createURI(predicate), objNode));
    }

    return model;
  }
Example #2
0
  public String GetResult() {
    String result_s = "";
    while (results.hasNext()) {
      QuerySolution row = results.next();
      // RDFNode thing= row.get("rule");
      // result_s = row.getLiteral("id").getString();

      result_s = result_s + row.getLiteral("id").getString() + ",";
    }
    if (!result_s.equals("")) {
      result_s = result_s.substring(0, result_s.length() - 1);
    }
    return result_s;
  }
  @Test
  public void testSelectToWurcsSparql() throws SparqlException, UnsupportedEncodingException {
    GlycoSequenceToWurcsSelectSparql s = new GlycoSequenceToWurcsSelectSparql("glycoct");
    SparqlEntity se = new SparqlEntity();
    se.setValue(
        GlycoSequenceToWurcsSelectSparql.FromSequence,
        "RES\n1b:a-dgal-HEX-1:5\n2s:n-acetyl\n3b:b-dgal-HEX-1:5\n4b:b-dglc-HEX-1:5\n5s:n-acetyl\n6b:b-dgal-HEX-1:5\n7b:a-lgal-HEX-1:5|6:d\n8b:b-dglc-HEX-1:5\n9s:n-acetyl\n10b:b-dglc-HEX-1:5\n11s:n-acetyl\n12b:b-dgal-HEX-1:5\n13b:a-lgal-HEX-1:5|6:d\nLIN\n1:1d(2+1)2n\n2:1o(3+1)3d\n3:3o(3+1)4d\n4:4d(2+1)5n\n5:4o(4+1)6d\n6:6o(2+1)7d\n7:3o(6+1)8d\n8:8d(2+1)9n\n9:1o(6+1)10d\n10:10d(2+1)11n\n11:10o(4+1)12d\n12:12o(2+1)13d"
            .replaceAll("\n", "\\\\n"));
    s.setSparqlEntity(se);
    logger.debug(s.getSparql());
    Query query =
        QueryFactory.create(s.getSparql().replaceAll("null", "").replace("?Sequence", ""));
    //        QueryExecution qe =
    // QueryExecutionFactory.sparqlService("http://localhost:3030/glycobase/query",query);
    QueryExecution qe =
        QueryExecutionFactory.sparqlService("http://test.ts.glytoucan.org/sparql", query);
    ResultSet rs = qe.execSelect();

    List<SparqlEntity> results = new ArrayList<SparqlEntity>();

    while (rs.hasNext()) {
      QuerySolution row = rs.next();
      Iterator<String> columns = row.varNames();
      SparqlEntity se2 = new SparqlEntity();
      while (columns.hasNext()) {
        String column = columns.next();
        RDFNode cell = row.get(column);

        if (cell.isResource()) {
          Resource resource = cell.asResource();
          // do something maybe with the OntModel???
          if (resource.isLiteral()) se.setValue(column, resource.asLiteral().getString());
          else se.setValue(column, resource.toString());
        } else if (cell.isLiteral()) {
          se.setValue(column, cell.asLiteral().getString());
        } else if (cell.isAnon()) {
          se.setValue(column, "anon");
        } else {
          se.setValue(column, cell.toString());
        }
      }
      results.add(se);
    }

    for (SparqlEntity entity : results) {
      System.out.println("results: " + entity.getValue("PrimaryId"));
    }
  }
  /**
   * Returns the string value of the first of the properties in the uriDescriptionList for the given
   * resource (as an URI). In case the resource does not have any of the properties mentioned, its
   * URI is returned. The value is obtained by querying the endpoint and the endpoint is queried
   * repeatedly until it gives a response (value or the lack of it)
   *
   * <p>It is highly recommended that the list contains properties like labels or titles, with test
   * values.
   *
   * @param uri - the URI for which a label is required
   * @return a String value, either a label for the parameter or its value if no label is obtained
   *     from the endpoint
   */
  private String getLabelForUri(String uri) {
    String result;

    if (uriLabelCache.containsKey(uri)) {
      return uriLabelCache.get(uri);
    }

    for (String prop : uriDescriptionList) {
      String innerQuery = "SELECT ?r WHERE {<" + uri + "> <" + prop + "> ?r } LIMIT 1";

      try {
        Query query = QueryFactory.create(innerQuery);
        QueryExecution qExec = QueryExecutionFactory.sparqlService(rdfEndpoint, query);
        boolean keepTrying = true;
        while (keepTrying) {
          keepTrying = false;
          try {
            ResultSet results = qExec.execSelect();

            if (results.hasNext()) {
              QuerySolution sol = results.nextSolution();
              result = EEASettings.parseForJson(sol.getLiteral("r").getLexicalForm());
              if (!result.isEmpty()) {
                uriLabelCache.put(uri, result);
                return result;
              }
            }
          } catch (Exception e) {
            keepTrying = true;
            logger.warn("Could not get label for uri {}. Retrying.", uri);
          } finally {
            qExec.close();
          }
        }
      } catch (QueryParseException qpe) {
        logger.error("Exception for query {}. The label cannot be obtained", innerQuery);
      }
    }
    return uri;
  }
  /**
   * Get a set of unique queryObjName returned from a select query
   *
   * <p>Used to retrieve sets of modified objects used in sync
   *
   * @param rdfQuery query to execute
   * @param queryObjName name of the object returned
   * @return set of values for queryObjectName in the rdfQuery result
   */
  HashSet<String> executeSyncQuery(String rdfQuery, String queryObjName) {
    HashSet<String> rdfUrls = new HashSet<String>();

    Query query;
    try {
      query = QueryFactory.create(rdfQuery);
    } catch (QueryParseException qpe) {
      logger.warn(
          "Could not parse [{}]. Please provide a relevant query. {}",
          rdfQuery,
          qpe.getLocalizedMessage());
      return null;
    }

    QueryExecution qExec = QueryExecutionFactory.sparqlService(rdfEndpoint, query);
    try {
      ResultSet results = qExec.execSelect();

      while (results.hasNext()) {
        QuerySolution sol = results.nextSolution();
        try {
          String value = sol.getResource(queryObjName).toString();
          rdfUrls.add(value);
        } catch (NoSuchElementException e) {
          logger.error("Encountered a NoSuchElementException: " + e.getLocalizedMessage());
          return null;
        }
      }
    } catch (Exception e) {
      logger.error(
          "Encountered a [{}] while querying the endpoint for sync", e.getLocalizedMessage());
      return null;
    } finally {
      qExec.close();
    }

    return rdfUrls;
  }
  @Override
  public EntityDefinition open(Assembler a, Resource root, Mode mode) {
    String prologue = "PREFIX : <" + NS + ">   PREFIX list: <http://jena.apache.org/ARQ/list#> ";
    Model model = root.getModel();

    String qs1 =
        StrUtils.strjoinNL(
            prologue,
            "SELECT * {",
            "  ?eMap  :entityField  ?entityField ;",
            "         :map ?map ;",
            "         :defaultField ?dftField .",
            "  OPTIONAL {",
            "    ?eMap :graphField ?graphField",
            "  }",
            "  OPTIONAL {",
            "    ?eMap :langField ?langField",
            "  }",
            "  OPTIONAL {",
            "    ?eMap :uidField ?uidField",
            "  }",
            "}");
    ParameterizedSparqlString pss = new ParameterizedSparqlString(qs1);
    pss.setIri("eMap", root.getURI());

    Query query1 = QueryFactory.create(pss.toString());
    QueryExecution qexec1 = QueryExecutionFactory.create(query1, model);
    ResultSet rs1 = qexec1.execSelect();
    List<QuerySolution> results = ResultSetFormatter.toList(rs1);
    if (results.size() == 0) {
      Log.warn(this, "Failed to find a valid EntityMap for : " + root);
      throw new TextIndexException("Failed to find a valid EntityMap for : " + root);
    }

    if (results.size() != 1) {
      Log.warn(this, "Multiple matches for EntityMap for : " + root);
      throw new TextIndexException("Multiple matches for EntityMap for : " + root);
    }

    QuerySolution qsol1 = results.get(0);
    String entityField = qsol1.getLiteral("entityField").getLexicalForm();
    String graphField =
        qsol1.contains("graphField") ? qsol1.getLiteral("graphField").getLexicalForm() : null;
    String langField =
        qsol1.contains("langField") ? qsol1.getLiteral("langField").getLexicalForm() : null;
    String defaultField =
        qsol1.contains("dftField") ? qsol1.getLiteral("dftField").getLexicalForm() : null;
    String uniqueIdField =
        qsol1.contains("uidField") ? qsol1.getLiteral("uidField").getLexicalForm() : null;

    Multimap<String, Node> mapDefs = HashMultimap.create();
    Map<String, Analyzer> analyzerDefs = new HashMap<>();

    Statement listStmt = root.getProperty(TextVocab.pMap);
    while (listStmt != null) {
      RDFNode n = listStmt.getObject();
      if (!n.isResource()) {
        throw new TextIndexException("Text list node is not a resource : " + n);
      }
      Resource listResource = n.asResource();
      if (listResource.equals(RDF.nil)) {
        break; // end of the list
      }

      Statement listEntryStmt = listResource.getProperty(RDF.first);
      if (listEntryStmt == null) {
        throw new TextIndexException("Text map list is not well formed.  No rdf:first property");
      }
      n = listEntryStmt.getObject();
      if (!n.isResource()) {
        throw new TextIndexException("Text map list entry is not a resource : " + n);
      }
      Resource listEntry = n.asResource();

      Statement fieldStatement = listEntry.getProperty(TextVocab.pField);
      if (fieldStatement == null) {
        throw new TextIndexException("Text map entry has no field property");
      }
      n = fieldStatement.getObject();
      if (!n.isLiteral()) {
        throw new TextIndexException("Text map entry field property has no literal value : " + n);
      }
      String field = n.asLiteral().getLexicalForm();

      Statement predicateStatement = listEntry.getProperty(TextVocab.pPredicate);
      if (predicateStatement == null) {
        throw new TextIndexException("Text map entry has no predicate property");
      }
      n = predicateStatement.getObject();
      if (!n.isURIResource()) {
        throw new TextIndexException(
            "Text map entry predicate property has non resource value : " + n);
      }
      mapDefs.put(field, n.asNode());

      Statement analyzerStatement = listEntry.getProperty(TextVocab.pAnalyzer);
      if (analyzerStatement != null) {
        n = analyzerStatement.getObject();
        if (!n.isResource()) {
          throw new TextIndexException("Text map entry analyzer property is not a resource : " + n);
        }
        Resource analyzerResource = n.asResource();
        Analyzer analyzer = (Analyzer) a.open(analyzerResource);
        analyzerDefs.put(field, analyzer);
      }

      // move on to the next element in the list
      listStmt = listResource.getProperty(RDF.rest);
    }

    // Primary field/predicate
    if (defaultField != null) {
      Collection<Node> c = mapDefs.get(defaultField);
      if (c.isEmpty())
        throw new TextIndexException("No definition of primary field '" + defaultField + "'");
    }

    EntityDefinition docDef = new EntityDefinition(entityField, defaultField);
    docDef.setGraphField(graphField);
    docDef.setLangField(langField);
    docDef.setUidField(uniqueIdField);
    for (String f : mapDefs.keys()) {
      for (Node p : mapDefs.get(f)) docDef.set(f, p);
    }
    for (String f : analyzerDefs.keySet()) {
      docDef.setAnalyzer(f, analyzerDefs.get(f));
    }
    return docDef;
  }
  @Test
  public void testDO() {
    String doid = "1485";
    String queryString =
        "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
            + "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
            + "prefix owl: <http://www.w3.org/2002/07/owl#>\n"
            + "\n"
            + "select ?s ?p ?o \n"
            + "from <http://purl.obolibrary.org/obo/merged/DOID>\n"
            + "\n"
            + "WHERE {\n"
            + "   <http://purl.obolibrary.org/obo/DOID_"
            + doid
            + "> ?p ?o\n"
            + "}";

    Query query = QueryFactory.create(queryString);
    QueryExecution qExe =
        QueryExecutionFactory.sparqlService("http://sparql.hegroup.org/sparql/", query);
    ResultSet results = qExe.execSelect();
    ResultSetFormatter.out(System.out, results, query);

    assertNotNull(results);

    /*Model model = ModelFactory.createDefaultModel();
    Selector selector = new SimpleSelector(null, model.getProperty("<http://www.geneontology.org/formats/oboInOwl#hasDbXref>"), (RDFNode) null);  // you need to cast the last null as otherwise the method is ambigious
    */

    List<String> dbXref = new ArrayList<>();
    List<String> iao = new ArrayList<>();
    List<String> exactSynonym = new ArrayList<>();
    List<String> alternativeId = new ArrayList<>();
    String diseaseLabel;

    while (results.hasNext()) {
      QuerySolution querySolution = results.nextSolution();

      if (querySolution.get("p").toString().matches("rdfs:label ")) {
        diseaseLabel = querySolution.get("o").toString();
      }

      if (querySolution
          .get("p")
          .toString()
          .matches("http://www.geneontology.org/formats/oboInOwl#hasDbXref")) {
        System.out.println(
            querySolution.get("p").toString() + "   " + querySolution.get("o").toString());
        dbXref.add(querySolution.get("o").toString());
      }

      if (querySolution.get("p").toString().matches("http://purl.obolibrary.org/obo/IAO_0000115")) {
        System.out.println(
            querySolution.get("p").toString() + "   " + querySolution.get("o").toString());
        iao.add(querySolution.get("o").toString());
      }

      if (querySolution
          .get("p")
          .toString()
          .matches("http://www.geneontology.org/formats/oboInOwl#hasExactSynonym")) {
        System.out.println(
            querySolution.get("p").toString() + "   " + querySolution.get("o").toString());
        exactSynonym.add(querySolution.get("o").toString());
      }

      if (querySolution
          .get("p")
          .toString()
          .matches("http://www.geneontology.org/formats/oboInOwl#hasAlternativeId")) {
        System.out.println(
            querySolution.get("p").toString() + "   " + querySolution.get("o").toString());
        alternativeId.add(querySolution.get("o").toString());
      }
    }

    assertNotNull(dbXref);
    assertNotNull(iao);
  }
  @Test
  public void testKBtoWurcsSparqlTranslation() throws SparqlException {

    List<Translation> translations = Ebean.find(Translation.class).findList();
    HashSet<String> resultList = new HashSet<>();

    String ct = "";

    for (Translation translation : translations) {
      System.out.println("id check " + translation.id + " ct " + translation.ct);
      if (translation.ct == null) continue;

      if (translation.structure.id > 0) {

        ct = translation.ct;

        GlycoSequenceToWurcsSelectSparql s = new GlycoSequenceToWurcsSelectSparql("glycoct");
        SparqlEntity se = new SparqlEntity();
        ct = StringUtils.chomp(ct);
        System.out.println("ct on top: " + ct);
        if (ct != null) {
          se.setValue(
              GlycoSequenceToWurcsSelectSparql.FromSequence,
              ct.replaceAll("\n", "\\\\n")
                  .replaceAll("x\\(", "u\\(")
                  .replaceAll("\\)x", "\\)u")
                  .trim());
          s.setSparqlEntity(se);
          logger.debug(s.getSparql());

          Query query =
              QueryFactory.create(s.getSparql().replaceAll("null", "").replace("?Sequence", ""));
          System.out.println(
              "Id "
                  + translation.structure.id
                  + " Query: "
                  + s.getSparql().replaceAll("null", "").replace("?Sequence", ""));
          QueryExecution qe =
              QueryExecutionFactory.sparqlService("http://test.ts.glytoucan.org/sparql", query);
          ResultSet rs = qe.execSelect();

          List<SparqlEntity> results = new ArrayList<>();
          HashSet<String> resultsList = new HashSet<>();

          while (rs.hasNext()) {
            QuerySolution row = rs.next();
            Iterator<String> columns = row.varNames();
            SparqlEntity se2 = new SparqlEntity();
            while (columns.hasNext()) {
              String column = columns.next();
              RDFNode cell = row.get(column);

              if (cell.isResource()) {
                Resource resource = cell.asResource();
                // do something maybe with the OntModel???
                if (resource.isLiteral()) se.setValue(column, resource.asLiteral().getString());
                else se.setValue(column, resource.toString());
              } else if (cell.isLiteral()) {
                se.setValue(column, cell.asLiteral().getString());
              } else if (cell.isAnon()) {
                se.setValue(column, "anon");
              } else {
                se.setValue(column, cell.toString());
              }
            }
            results.add(se);
          }

          for (SparqlEntity entity : results) {
            // System.out.println("results: " + entity.getValue("PrimaryId"));
            resultList.add(
                translation.structure.id + "\t" + entity.getValue("PrimaryId").toString());
          }
        }
      }
    }

    for (String c : resultList) {
      System.out.println(c);
    }
  }
  @Test
  public void testKBtoWurcsSparql() throws SparqlException {

    List<Structure> structures = Ebean.find(Structure.class).findList();
    HashSet<String> resultList = new HashSet<>();

    String ct = "";

    for (Structure structure : structures) {
      if (structure.id >= 7400) {

        if (structure.glycanst.startsWith("v--")) {
          structure.glycanst = structure.glycanst.replace("v--", "FreeEnd--");
        }

        if (structure.glycanst.startsWith("FreenEnd")) {
          structure.glycanst = structure.glycanst.replace("FreenEnd", "FreeEnd");
        }

        if (structure.glycanst.startsWith("FreeEnd?")) {
          structure.glycanst = structure.glycanst.replace("FreeEnd?", "FreeEnd--?");
        }

        if (structure.glycanst.startsWith("<Gly") || structure.glycanst.contains("0.0000u")) {
          continue;
        }

        System.out.println(structure.getGlycanst());

        BuilderWorkspace workspace = new BuilderWorkspace(new GlycanRendererAWT());
        workspace.setNotation("cfg"); // cfgbw | uoxf | uoxfcol | text
        GlycanRenderer renderer = workspace.getGlycanRenderer();
        org.eurocarbdb.application.glycanbuilder.Glycan glycan =
            org.eurocarbdb.application.glycanbuilder.Glycan.fromString(structure.glycanst.trim());
        if (glycan != null) {
          ct = glycan.toGlycoCTCondensed();
          System.out.println("this was the ct: " + ct);
          GlycoSequenceToWurcsSelectSparql s = new GlycoSequenceToWurcsSelectSparql("glycoct");
          SparqlEntity se = new SparqlEntity();
          ct = StringUtils.chomp(ct);
          se.setValue(
              GlycoSequenceToWurcsSelectSparql.FromSequence,
              ct.replaceAll("\n", "\\\\n")
                  .replaceAll("x\\(", "u\\(")
                  .replaceAll("\\)x", "\\)u")
                  .trim());
          s.setSparqlEntity(se);
          logger.debug(s.getSparql());

          Query query =
              QueryFactory.create(s.getSparql().replaceAll("null", "").replace("?Sequence", ""));
          System.out.println(
              "Id "
                  + structure.id
                  + " Query: "
                  + s.getSparql().replaceAll("null", "").replace("?Sequence", ""));
          QueryExecution qe =
              QueryExecutionFactory.sparqlService("http://test.ts.glytoucan.org/sparql", query);
          ResultSet rs = qe.execSelect();

          List<SparqlEntity> results = new ArrayList<>();
          HashSet<String> resultsList = new HashSet<>();

          while (rs.hasNext()) {
            QuerySolution row = rs.next();
            Iterator<String> columns = row.varNames();
            SparqlEntity se2 = new SparqlEntity();
            while (columns.hasNext()) {
              String column = columns.next();
              RDFNode cell = row.get(column);

              if (cell.isResource()) {
                Resource resource = cell.asResource();
                // do something maybe with the OntModel???
                if (resource.isLiteral()) se.setValue(column, resource.asLiteral().getString());
                else se.setValue(column, resource.toString());
              } else if (cell.isLiteral()) {
                se.setValue(column, cell.asLiteral().getString());
              } else if (cell.isAnon()) {
                se.setValue(column, "anon");
              } else {
                se.setValue(column, cell.toString());
              }
            }
            results.add(se);
          }

          for (SparqlEntity entity : results) {
            // System.out.println("results: " + entity.getValue("PrimaryId"));
            resultList.add(structure.id + "\t" + entity.getValue("PrimaryId").toString());
          }
        }
      }
    }
    PrintWriter writer = null;
    try {
      writer =
          new PrintWriter(
              new OutputStreamWriter(new FileOutputStream("/tmp/HashSet.txt"), "UTF-8"));
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
    for (String c : resultList) {
      System.out.println(c);
      writer.println(c);
    }
  }
  /**
   * A method to build a collection of collaborator objects representing a network based on an
   * organisation
   *
   * @param id the id of the central organisation
   * @param radius the number of edges required from the central contributor
   * @return the collection of collaborator objects
   */
  @SuppressWarnings("rawtypes")
  public TreeMap<Integer, Collaborator> getRawCollaboratorData_org(String id, int radius) {

    // check the parameters
    if (InputUtils.isValidInt(id) == false) {
      throw new IllegalArgumentException("Error: the id parameter is required");
    }

    if (InputUtils.isValidInt(radius, ExportServlet.MIN_DEGREES, ExportServlet.MAX_DEGREES)
        == false) {
      throw new IllegalArgumentException(
          "Error: the radius parameter must be between "
              + ExportServlet.MIN_DEGREES
              + " and "
              + ExportServlet.MAX_DEGREES);
    }

    // define helper variables
    // collection of collaborators
    java.util.TreeMap<Integer, Collaborator> cId_cObj_map =
        new java.util.TreeMap<Integer, Collaborator>();

    // set of collaborators that we've already processed
    java.util.TreeSet<Integer> foundCollaboratorsSet = new java.util.TreeSet<Integer>();

    // define other helper variables
    String contributor_id = null;
    QuerySolution row = null;
    Collaborator collaborator = null;

    String sql =
        "SELECT DISTINCT b.eventid   "
            + "FROM events a, orgevlink b "
            + "WHERE b.organisationid = ? " // +id
            + "AND a.eventid = b.eventid";

    int[] param = {Integer.parseInt(id)};
    java.sql.ResultSet resultSet = db.exePreparedStatement(sql, param);

    ArrayList<String> eventResults = new ArrayList<String>();

    try {
      //		 	check to see that data was returned
      if (!resultSet.last()) {
        db.tidyup();
        return null;
      } else resultSet.beforeFirst();

      // loop through the resultset
      while (resultSet.next() == true) {
        eventResults.add(resultSet.getString(1));
      }

    } catch (java.sql.SQLException ex) {
      System.out.println("Exception: " + ex.getMessage());
      resultSet = null;
    }

    db.tidyup();

    // helper
    int first = 0;

    // define the query
    String sparqlQuery1 =
        "PREFIX foaf:       <"
            + FOAF.NS
            + "> "
            + "PREFIX ausestage:  <"
            + AuseStage.NS
            + "> "
            + "PREFIX event:      <http://purl.org/NET/c4dm/event.owl#> "
            + "PREFIX dcterms:    <http://purl.org/dc/terms/> "
            + "SELECT DISTINCT ?agent ?givenName ?familyName "
            + "WHERE { ";
    for (String event : eventResults) {
      if (first > 0) {
        sparqlQuery1 += "UNION ";
      }
      first++;

      sparqlQuery1 +=
          "{<ausstage:e:"
              + event
              + "> a                event:Event; "
              + "   event:agent      ?agent. "
              + "	?agent             a                foaf:Person; "
              + "   foaf:givenName   ?givenName; "
              + "   foaf:familyName  ?familyName. "
              + " } ";
    }
    sparqlQuery1 += " } ";

    // execute query
    ResultSet results = rdf.executeSparqlQuery(sparqlQuery1);

    // now we transfer the results to a TreeMap <Integer,
    while (results.hasNext()) {

      row = results.nextSolution();

      contributor_id = AusStageURI.getId(row.get("agent").toString());

      collaborator = new Collaborator(contributor_id);

      cId_cObj_map.put(Integer.parseInt(contributor_id), collaborator);
      foundCollaboratorsSet.add(Integer.parseInt(contributor_id));
    }

    rdf.tidyUp();

    return cId_cObj_map;
  } // end getRawCollaboratorData_org method
  /*
   * 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;
  }