修正比较算法
This commit is contained in:
parent
71d7de9f18
commit
5a4369d7cc
|
@ -393,11 +393,9 @@ std::shared_ptr<FragmentNode> FragmentLayerCheck::_sets_fill(std::shared_ptr<con
|
|||
auto ptr = _sets_fill(nis);
|
||||
if (ptr) list << ptr;
|
||||
}
|
||||
for (auto node = ++list.begin(); node != list.end(); ++node) {
|
||||
auto prev = *(node - 1);
|
||||
auto curr = *node;
|
||||
prev->appendNext(curr);
|
||||
}
|
||||
for (auto nitr = ++list.begin(); nitr != list.end(); nitr++)
|
||||
(*(nitr-1))->appendNext(*nitr);
|
||||
|
||||
if (list.size())
|
||||
this->_story_start << list.first();
|
||||
}
|
||||
|
@ -414,7 +412,7 @@ void FragmentLayerCheck::_refers_rebuild(std::shared_ptr<const FragmentNode> nod
|
|||
auto fragm = std::static_pointer_cast<const FragmentSlice>(node->bind()->element());
|
||||
for (auto node_t : fragm->children()) {
|
||||
auto refn = std::dynamic_pointer_cast<const FragmentRefers>(node_t);
|
||||
if(refn){
|
||||
if (refn) {
|
||||
auto target_node = _node_set[refn->referSignature()];
|
||||
std::const_pointer_cast<FragmentNode>(node)->appendNext(target_node);
|
||||
}
|
||||
|
@ -429,6 +427,7 @@ void FragmentLayerCheck::node_relayer(std::shared_ptr<FragmentNode> node, int cu
|
|||
for (auto nis : node->referNodes())
|
||||
node_relayer(nis, curr_num + 1);
|
||||
}
|
||||
qDebug() << node->bind()->element()->signature() << node->layerNumber();
|
||||
}
|
||||
|
||||
|
||||
|
@ -442,7 +441,7 @@ void FragmentLayerCheck::layer_check(std::shared_ptr<const ElementAccess> node)
|
|||
story_layer_check(node);
|
||||
break;
|
||||
default:
|
||||
for(auto ins : node->children())
|
||||
for (auto ins : node->children())
|
||||
layer_check(ins);
|
||||
break;
|
||||
}
|
||||
|
@ -450,45 +449,50 @@ void FragmentLayerCheck::layer_check(std::shared_ptr<const ElementAccess> node)
|
|||
|
||||
void FragmentLayerCheck::story_layer_check(std::shared_ptr<const ast_gen::ElementAccess> story) {
|
||||
auto fragms_list = story->children();
|
||||
auto story_nm = story->element()->signature();
|
||||
|
||||
decltype(fragms_list) real_elms;
|
||||
std::copy_if(fragms_list.begin(), fragms_list.end(), std::back_inserter(real_elms),
|
||||
[](std::shared_ptr<const ast_gen::ElementAccess> ins) { return ins->element()->typeMark() == (int) NovelNode::FragmentSlice; });
|
||||
|
||||
for (auto curr = ++real_elms.begin(); curr != real_elms.end(); ++curr) {
|
||||
auto prev = curr - 1;
|
||||
auto curr_sign = (*curr)->element()->signature();
|
||||
auto prev_sign = (*prev)->element()->signature();
|
||||
|
||||
sibling_element_compair(_node_set[prev_sign], _node_set[curr_sign]);
|
||||
auto prev_it = curr - 1;
|
||||
auto curr_it = curr;
|
||||
for (; curr_it != real_elms.end(); ++curr_it) {
|
||||
auto curr_sign = (*curr_it)->element()->signature();
|
||||
auto prev_sign = (*prev_it)->element()->signature();
|
||||
sibling_element_compair(story_nm, _node_set[prev_sign], _node_set[curr_sign]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FragmentLayerCheck::sibling_element_compair(std::shared_ptr<const FragmentNode> prev, std::shared_ptr<const FragmentNode> curr) {
|
||||
auto prev_childs = prev->referNodes();
|
||||
auto curr_childs = curr->referNodes();
|
||||
void FragmentLayerCheck::sibling_element_compair(const QString& story, std::shared_ptr<const FragmentNode> prev, std::shared_ptr<const FragmentNode> curr) {
|
||||
auto prev_childs_o = prev->referNodes();
|
||||
auto curr_childs_o = curr->referNodes();
|
||||
auto vpeak = [=](std::shared_ptr<const FragmentNode> ins) { return !ins->bind()->element()->signature().startsWith(story); };
|
||||
|
||||
QList<int> prev_layers;
|
||||
std::transform(prev_childs.begin(), prev_childs.end(), std::back_inserter(prev_layers),
|
||||
[](std::shared_ptr<const FragmentNode> ins) { return ins->layerNumber(); });
|
||||
decltype(prev_childs_o) prev_childs;
|
||||
std::copy_if(prev_childs_o.begin(), prev_childs_o.end(), std::back_inserter(prev_childs), vpeak);
|
||||
decltype(curr_childs_o) curr_childs;
|
||||
std::copy_if(curr_childs_o.begin(), curr_childs_o.end(), std::back_inserter(curr_childs), vpeak);
|
||||
|
||||
QList<int> next_layers;
|
||||
std::transform(curr_childs.begin(), curr_childs.end(), std::back_inserter(next_layers),
|
||||
[](std::shared_ptr<const FragmentNode> ins) { return ins->layerNumber(); });
|
||||
if (!curr_childs.size() || !prev_childs.size())
|
||||
return;
|
||||
|
||||
auto min0 = *std::min_element(prev_layers.begin(), prev_layers.end());
|
||||
auto max1 = *std::max_element(next_layers.begin(), next_layers.end());
|
||||
auto max_e0 = *std::max_element(prev_childs.begin(), prev_childs.end(),
|
||||
[](std::shared_ptr<const FragmentNode> a, std::shared_ptr<const FragmentNode> b){
|
||||
return a->layerNumber() < b->layerNumber();
|
||||
});
|
||||
auto min_e1 = *std::min_element(curr_childs.begin(), curr_childs.end(),
|
||||
[](std::shared_ptr<const FragmentNode> a, std::shared_ptr<const FragmentNode> b) {
|
||||
return a->layerNumber() < b->layerNumber();
|
||||
});
|
||||
|
||||
if (next_layers.size() && min0 > max1) {
|
||||
decltype(prev_childs) tempx;
|
||||
std::copy_if(curr_childs.begin(), curr_childs.end(), std::back_inserter(tempx),
|
||||
[=](std::shared_ptr<const FragmentNode> ins) { return ins->layerNumber() >= min0; });
|
||||
QStringList names;
|
||||
std::transform(tempx.begin(), tempx.end(), std::back_inserter(names),
|
||||
[=](std::shared_ptr<const FragmentNode> ins) { return ins->bind()->element()->signature(); });
|
||||
|
||||
throw new CheckException(QString("CheckError[0x0009]情节时间序错误!%1->%2\n\t\t%3->{%4}")
|
||||
if (curr_childs.size() && max_e0->layerNumber() > min_e1->layerNumber()) {
|
||||
throw new CheckException(QString("CheckError[0x0009]情节时间序错误!%1 && %2\n\t\t%3->%4@%5\n\t\t%6->%7@%8")
|
||||
.arg(prev->bind()->element()->signature()).arg(curr->bind()->element()->signature())
|
||||
.arg(curr->bind()->element()->signature(), names.join(",")));
|
||||
.arg(prev->bind()->element()->signature(), max_e0->bind()->element()->signature(), QString("%1").arg(max_e0->layerNumber()))
|
||||
.arg(curr->bind()->element()->signature(), min_e1->bind()->element()->signature(), QString("%1").arg(min_e1->layerNumber())));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -156,7 +156,7 @@ namespace example_novel {
|
|||
/// <param name="node">故事线</param>
|
||||
void layer_check(std::shared_ptr<const ast_gen::ElementAccess> node);
|
||||
void story_layer_check(std::shared_ptr<const ast_gen::ElementAccess> story);
|
||||
void sibling_element_compair(std::shared_ptr<const FragmentNode> prev, std::shared_ptr<const FragmentNode> curr);
|
||||
void sibling_element_compair(const QString& story, std::shared_ptr<const FragmentNode> prev, std::shared_ptr<const FragmentNode> curr);
|
||||
|
||||
public:
|
||||
// 通过 CheckProvider 继承
|
||||
|
|
Loading…
Reference in New Issue