尝试创建一个输入为
的AI机器人程序"Search <START:engine> google <END> for <START:query> London Bridge <END>"
输出为
var getAllBetween = function (firstEl, lastEl) {
var firstElement = $(firstEl); // First Element
var lastElement = $(lastEl); // Last Element
var collection = new Array(); // Collection of Elements
collection.push(firstElement.attr('id')); // Add First Element to Collection
$(firstEl).nextAll().each(function () { // Traverse all siblings
var siblingID = $(this).attr('id'); // Get Sibling ID
if (siblingID !== $(lastElement).attr('id')) { // If Sib is not LastElement
collection.push($(this).attr('id')); // Add Sibling to Collection
} else { // Else, if Sib is LastElement
collection.push(lastElement.attr('id')); // Add Last Element to Collection
return false; // Break Loop
}
});
return collection; // Return Collection
};
$("#editable").mouseup(function () {
if (window.getSelection) {
userSelection = window.getSelection();
rangeObject = userSelection.getRangeAt(0);
if (rangeObject.startContainer === rangeObject.endContainer) {
alert(rangeObject.startContainer.parentNode.id);
} else {
alert(getAllBetween(
rangeObject.startContainer.parentNode,
rangeObject.endContainer.parentNode));
}
}
});
问题是这些XML标签不能互相重叠,不能扩展为多个单词,上面的示例在引擎括号中使用单个单词,但是在查询中我们可以有多个单词括号。
示例代码允许我选择单词,但不能处理重叠的括号。
@for (int i = 0; i < sentences.Length; i++)
{
var phrase = sentences[i].Split(' ');
<p id="editable">
@for (int p = 0; p < phrase.Length; p++)
{
<span id="phrase-@i-@p">@phrase[p]</span>
}
</p>
}
使用剃须刀:
{{1}}
不确定是否应使用Angularjs或VueJs重写它,以创建更多动态作为Luis.ai或DialogFlow