在用户提供的任何科学论文中,程序必须.
1.a -数字引文。
这些方法不是从总结的文本中复制完整的句子,而是压缩句子1、4-6,或者从头开始重新生成3中的新句子。
1.b -论文末尾的APA引用&只是作者的名字+年份。
这些方法不是从总结的文本中复制完整的句子,而是压缩句子(Jing 2000;Knight和Marcu 2000;Sporleder和Lapata 2005;Steinberger和Ježek 2006),或者从零开始重新生成新的句子(McKeown等人,1999年)。
我认为准则是:
"\[(\d.*?)\]"
用于数字引文。
"\d+([\.]([\ ])(([\D*])*([\,]))*([\ ][\w][\.]))|[\d]{4}"
APA的引文风格。
我的问题是如何取代第一个模式中的第二个模式?
发布于 2015-12-23 19:26:29
使用String.prototype.replace()
与回调函数一起使用,该函数将数字字符串(以逗号分隔,可能是一个范围)拆分为一个数字数组。然后循环遍历数字,并使用其他正则表达式查找作者/年份。然后加入这些字符串并返回它以进行替换。
var string = `Instead of reproducing full sentences from the summarized text, these methods either compress the sentences [1, 4-6], or re-generate new sentences from scratch [3].
1. Jing, H.: Sentence Reduction for Automatic Text Summarization. In Proceedings of the 6th Applied Natural Language Processing Conference, Seattle, USA, 2000, pp. 310–315.
3. McKeown et al: Sentence Reduction for Automatic Text Summarization. In Proceedings of the 6th Applied Natural Language Processing Conference, Seattle, USA, 1999, pp. 310–315.
4. Knight and Marcu.: Sentence Reduction for Automatic Text Summarization. In Proceedings of the 6th Applied Natural Language Processing Conference, Seattle, USA, 2000, pp. 310–315.
5. Sporleder and Lapata: Sentence Reduction for Automatic Text Summarization. In Proceedings of the 6th Applied Natural Language Processing Conference, Seattle, USA, 2005, pp. 310–315.
6. Steinberger and Ježek: Sentence Reduction for Automatic Text Summarization. In Proceedings of the 6th Applied Natural Language Processing Conference, Seattle, USA, 2006, pp. 310–315.`;
string.replace(/\[(\d[^\]]*)\]/g, function(matches, reference) {
var numbers = [],
authors = [];
reference.split(/,\s*/g).forEach(function(number) {
if(number.indexOf('-') !== -1) {
var range = number.split('-');
for(var i = range[0]; i <= range[1]; i++) {
numbers.push(i);
}
} else numbers.push(number);
});
numbers.forEach(function(number) {
var regex = new RegExp(number + '\\. ([^:]+):.*?(\\d{4})'),
matches = regex.exec(string);
authors.push(matches[1] + ' ' + matches[2]);
});
return '(' + authors.join('; ') + ')';
});
https://stackoverflow.com/questions/34440010
复制相似问题