Beispiel #1
0
 public Instance getDbInstance(int index) {
   Instance instance = new Instance(InstanceType.GOLD);
   Connection connection = null;
   try {
     connection = DbManager.getConnection();
     String query =
         "SELECT I.id AS id, I.text AS text, AI.codes AS codes, AI.time_spent AS time_spent "
             + "FROM AnnotationInstance AI "
             + "JOIN Instance I ON AI.instance_id = I.id "
             + "WHERE AI.pid=? AND AI.`index`=?";
     PreparedStatement statement = connection.prepareStatement(query);
     statement.setString(1, getPid());
     statement.setInt(2, index);
     ResultSet resultSet = statement.executeQuery();
     while (resultSet.next()) {
       instance.setId(resultSet.getInt("id"));
       instance.setText(resultSet.getString("text"));
       instance.setCodes(toInstanceCodes(resultSet.getString("codes")));
       instance.setTimeSpent(resultSet.getInt("time_spent"));
     }
     resultSet.close();
     statement.close();
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     try {
       if (null != connection) connection.close();
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
   return instance;
 }
Beispiel #2
0
 public List<Instance> getInstances() {
   List<Instance> instances = new ArrayList<Instance>();
   Connection connection = null;
   try {
     connection = DbManager.getConnection();
     String query =
         "SELECT I.id AS id, I.message_id AS message_id, AI.codes AS codes "
             + "FROM AnnotationInstance AI "
             + "JOIN Instance I ON AI.instance_id = I.id "
             + "WHERE AI.pid=? ORDER BY AI.`index` ASC";
     PreparedStatement statement = connection.prepareStatement(query);
     statement.setString(1, getPid());
     ResultSet resultSet = statement.executeQuery();
     while (resultSet.next()) {
       Instance instance = new Instance(InstanceType.GOLD);
       instance.setId(resultSet.getInt("id"));
       instance.setMessageId(resultSet.getString("message_id"));
       instance.setCodes(toInstanceCodes(resultSet.getString("codes")));
       instances.add(instance);
     }
     resultSet.close();
     statement.close();
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     try {
       if (null != connection) connection.close();
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
   return instances;
 }
Beispiel #3
0
  public MLInstance(Instance instance, CodeBook codebook) {
    messageID = instance.getMessageId();
    instID = String.valueOf(instance.getId());
    sentence = instance;
    tokens = Arrays.asList(instance.getTokens());
    posTags = Arrays.asList(sentence.getPOSTags());
    // what is this for unlabeled
    // check for null or empty list
    classLabels = instance.getCodes();
    // check if classLabels is null
    // get codebook from docID

    humanLabels = new ArrayList<String>();
    String humanLabel;
    if (classLabels != null) {
      for (String label : classLabels) {
        humanLabel = codebook.getLabel(label);
        humanLabels.add(humanLabel);
      }
    }
    // document level data
    docSender = instance.getMessageFrom();

    // silver instance information

    if (instance.getInstanceType() == InstanceType.SILVER) {
      isSilverCollection = true;
      silverCode = instance.getSilverCode();
      // check these labels, is one unverified?
      silverVerificationLabel = instance.getVerificationType();
    }
  }
Beispiel #4
0
 // test to see if this instance is in a list of repository instances
 public boolean containedInSilverInstanceList(List<Instance> instanceList) {
   if (instanceList == null) {
     return false;
   }
   for (Instance instance : instanceList) {
     if (this.getInstanceID().equals(String.valueOf(instance.getId()))) {
       return true;
     }
   }
   // if not found in loop, return false
   return false;
 }
Beispiel #5
0
 public String toStringSilver() {
   String result =
       "MLInstance (Silver): "
           + messageID
           + ", "
           + instID
           + "  "
           + sentence.getText()
           + "  "
           + silverCode
           + " "
           + silverVerificationLabel;
   return result;
 }
Beispiel #6
0
 public String toString() {
   String result =
       "MLInstance (Gold): "
           + messageID
           + ", "
           + instID
           + "  "
           + sentence.getText()
           + "  "
           + classLabels
           + " "
           + humanLabels;
   return result;
 }
Beispiel #7
0
  /*
   *  This constructor for use with gold documents from repository with tokens and labels
   *     (possibly null) sender
   */
  public MLInstance(
      String messageID,
      String sentID,
      Instance sentence,
      List<String> toks,
      List<String> labels,
      List<String> humanLabels,
      String docSender) {
    this.messageID = messageID;
    instID = sentID;
    this.sentence = sentence;
    tokens = toks;
    // assume that the Instance class returns the tokens and pos tags in order
    this.posTags = Arrays.asList(sentence.getPOSTags());
    classLabels = labels;
    this.humanLabels = humanLabels;
    this.docSender = docSender;

    isSilverCollection = false;
  }
Beispiel #8
0
 /*
  *  This constructor for use with silver instances from repository with tokens and verified codes
  *     (possibly null) sender
  */
 public MLInstance(
     String messageID,
     String sentID,
     Instance sentence,
     List<String> toks,
     String code,
     VerificationType label,
     String docSender) {
   this.messageID = messageID;
   instID = sentID;
   this.sentence = sentence;
   tokens = toks;
   // assume that the Instance class returns the tokens and pos tags in order
   this.posTags = Arrays.asList(sentence.getPOSTags());
   silverVerificationLabel = label;
   silverCode = code;
   this.docSender = docSender;
   // class label list is empty
   classLabels = new ArrayList<String>();
   isSilverCollection = true;
 }
Beispiel #9
0
 public String getInstanceText() {
   return sentence.getText();
 }