Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var findKeywords = function( headline, body, n, keywordArgs ){
keywordArgs = keywordArgs || { language:"english", return_changed_case:true };
body = body.split(' ');
// Extract keywords from headline. Returns an array
keywordArray = extractor.extract( headline, keywordArgs );
// if no N is given, set n to max length. // todo: just set to infinity?
n = n || keywordArray.length;
// Create object to track each mention of keyword in summary
keywordCount = {};
keywordArray.map(function(word){ keywordCount[word] = 0; });
// Iterate over summary to count mentions of each keyword
for ( var i = 0; i < body.length; i++ ) {
for (word in keywordCount) {
// console.log(word, body[i]);
if (word === body[i]){
keywordCount[word] += 1;
}
}
// First get the words
// Question
const keywords = item.q.split(' ').map(stemmer)
for (const word of keywords) {
if (!invertedIndexes[word]) {
invertedIndexes[word] = []
invertedIndexes[word][contentIndex] = [contentIndex, QUESTION_POINTS]
} else if (!invertedIndexes[word][contentIndex]) {
invertedIndexes[word][contentIndex] = [contentIndex, QUESTION_POINTS]
} else {
invertedIndexes[word][contentIndex][1] += QUESTION_POINTS
}
}
// Answer
const answerKeywords = keywordExtractor.extract(item.a, extractorOptions).map(stemmer)
for (const word of answerKeywords) {
if (!invertedIndexes[word]) {
invertedIndexes[word] = []
invertedIndexes[word][contentIndex] = [contentIndex, ANSWER_POINTS]
} else if (!invertedIndexes[word][contentIndex]) {
invertedIndexes[word][contentIndex] = [contentIndex, ANSWER_POINTS]
} else {
invertedIndexes[word][contentIndex][1] += ANSWER_POINTS
}
}
// Tags. Give half points for each word if it's a multi-word tag
const halfTags = []
const tags = []
item.t.forEach(item => {
tags.push(stemmer(item))
}).map(function(v) {
// for each document extract only certain properties
var index = tokenizer.extract(
['events', 'properties', 'methods', 'name', 'codeName', 'renderedContent', 'docType'].map(function(k) {
if ('string' === typeof v[k]) {
// rendered content should be cleaned a bit
return 'renderedContent' === k ? cleanText(v[k]) : v[k];
} else if (v[k]) {
var m = v[k];
return [m.codeName || '',
m.name || '',
cleanText(m.renderedContent || ''),
m.alias || '',
m.eventTarget || '',
m.eventType || ''
].join(' ');
} else {
return '';
}
errorWrap(async (req, res) => {
const data = req.body;
const created_tags = extractor.extract(data.notes, {
language: "english",
remove_digits: true,
return_changed_case: true,
remove_duplicates: true
});
const latlng = await resourceUtils.addressToLatLong(data.address);
data.location.coordinates[0] = latlng.lng;
data.location.coordinates[1] = latlng.lat;
data.federalRegion = latlng.region;
const newResource = new Resource(data);
newResource.tags = created_tags;
await newResource.save();
getKeywords = str => {
return keywords.extract(str, {
language: cfg.keywords,
remove_digits: true,
return_changed_case: true,
remove_duplicates: true
}).join(' ')
},
setContent = (obj, item, ref) => {
export function getKeywords (str, language) {
const keywords = extract(str, {
language,
remove_digits: true,
return_changed_case: true,
remove_duplicates: true
})
return keywords.join(' ')
}
exports = module.exports = function(text) {
return (keywordExtractor.extract(text, keywordOptions) || []).slice(0, 5);
};