void DependencyLabelerParts::BuildArcIndices(const std::vector<int> &heads) {
  DeleteArcIndices();
  index_arcs_.assign(heads.size(), std::vector<int>(0));

  int offset, num_arcs;
  GetOffsetArc(&offset, &num_arcs);
  for (int r = 0; r < num_arcs; ++r) {
    Part *part = (*this)[offset + r];
    CHECK(part->type() == DEPENDENCYLABELERPART_ARC);
    int m = static_cast<DependencyLabelerPartArc*>(part)->modifier();
    index_arcs_[m].push_back(offset + r);
  }
}
示例#2
0
void DependencyParts::BuildIndices(int sentence_length, bool labeled) {
  DeleteIndices();
  index_.resize(sentence_length);
  for (int h = 0; h < sentence_length; ++h) {
    index_[h].resize(sentence_length);
    for (int m = 0; m < sentence_length; ++m) {
      index_[h][m] = -1;
    }
  }

  int offset, num_basic_parts;
  GetOffsetArc(&offset, &num_basic_parts);
  for (int r = 0; r < num_basic_parts; ++r) {
    Part *part = (*this)[offset + r];
    CHECK(part->type() == DEPENDENCYPART_ARC);
    int h = static_cast<DependencyPartArc*>(part)->head();
    int m = static_cast<DependencyPartArc*>(part)->modifier();
    index_[h][m] = offset + r;
  }

  if (labeled) {
    index_labeled_.resize(sentence_length);
    for (int h = 0; h < sentence_length; ++h) {
      index_labeled_[h].resize(sentence_length);
      for (int m = 0; m < sentence_length; ++m) {
        index_labeled_[h][m].clear();
      }
    }

    int offset, num_labeled_arcs;
    GetOffsetLabeledArc(&offset, &num_labeled_arcs);
    for (int r = 0; r < num_labeled_arcs; ++r) {
      Part *part = (*this)[offset + r];
      CHECK(part->type() == DEPENDENCYPART_LABELEDARC);
      int h = static_cast<DependencyPartLabeledArc*>(part)->head();
      int m = static_cast<DependencyPartLabeledArc*>(part)->modifier();
      index_labeled_[h][m].push_back(offset + r);
    }
  }
}
示例#3
0
void SemanticParts::BuildIndices(int sentence_length, bool labeled) {
  DeleteIndices();

  int offset, num_basic_parts;
  GetOffsetArc(&offset, &num_basic_parts);
  index_senses_.resize(sentence_length);
  for (int r = 0; r < num_basic_parts; ++r) {
    Part *part = (*this)[offset + r];
    CHECK(part->type() == SEMANTICPART_ARC) << part->type();
    int p = static_cast<SemanticPartArc*>(part)->predicate();
    int s = static_cast<SemanticPartArc*>(part)->sense();
    int k = 0;
    for (; k < index_senses_[p].size(); ++k) {
      if (index_senses_[p][k] == s) break;
    }
    if (k == index_senses_[p].size()) {
      index_senses_[p].push_back(s);
    }
  }

  index_.resize(sentence_length);
  for (int p = 0; p < sentence_length; ++p) {
    index_[p].resize(sentence_length);
    for (int a = 0; a < sentence_length; ++a) {
      index_[p][a].clear();
    }
  }

  for (int r = 0; r < num_basic_parts; ++r) {
    Part *part = (*this)[offset + r];
    CHECK(part->type() == SEMANTICPART_ARC);
    int p = static_cast<SemanticPartArc*>(part)->predicate();
    int a = static_cast<SemanticPartArc*>(part)->argument();
    int s = static_cast<SemanticPartArc*>(part)->sense();
    if (s >= index_[p][a].size()) index_[p][a].resize(s+1, -1);
    index_[p][a][s] = offset + r;
  }

  if (labeled) {
    index_labeled_.resize(sentence_length);
    for (int p = 0; p < sentence_length; ++p) {
      index_labeled_[p].resize(sentence_length);
      for (int a = 0; a < sentence_length; ++a) {
        index_labeled_[p][a].clear();
      }
    }

    int offset, num_labeled_arcs;
    GetOffsetLabeledArc(&offset, &num_labeled_arcs);
    for (int r = 0; r < num_labeled_arcs; ++r) {
      Part *part = (*this)[offset + r];
      CHECK(part->type() == SEMANTICPART_LABELEDARC);
      int p = static_cast<SemanticPartLabeledArc*>(part)->predicate();
      int a = static_cast<SemanticPartLabeledArc*>(part)->argument();
      int s = static_cast<SemanticPartLabeledArc*>(part)->sense();
      //int role = static_cast<SemanticPartLabeledArc*>(part)->role();
      if (s >= index_labeled_[p][a].size()) index_labeled_[p][a].resize(s+1);
      //if (role >= index_labeled_[p][a][s].size()) {
      //  index_labeled_[p][a][s].resize(role+1, -1);
      //}
      //index_labeled_[p][a][s][role] = offset + r;
      index_labeled_[p][a][s].push_back(offset + r);
    }
  }
}