Skip to content

Commit

Permalink
fixed all files, filetype is given through input, so no checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Duc Nguyen committed Dec 5, 2016
1 parent bae389f commit e26d8cd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 45 deletions.
3 changes: 1 addition & 2 deletions config/index.js
Expand Up @@ -16,8 +16,7 @@ config.scoreManager = {
// similar-title-plugin pulls file.name from file and tasks[].name from tasks[] itself
'similar-file-title-task-title': {
use: 'similar-context-plugin',
inputs: ['file.name', 'tasks[].name'],
params: { 'fileType': 'file.type' }
inputs: ['file.name', 'tasks[].name']
},
// timestamp comparison defaults to 600 sec
'context-file-timestamp-tasks-timestamp': {
Expand Down
14 changes: 0 additions & 14 deletions lib/plugins/similar-context-plugin.js
Expand Up @@ -7,36 +7,22 @@ const utils = require('../utils.js')
* Returns a comparing score of two strings based on Dice's Coefficient using the stringSimilarity module.
*
* If param 'extractKeywords' is true: first uses the keyword-extractor to get the keywords, then compares the keywords with stringSimilarity to get a context score
* Param 'fileType' by default false:
* No cutting of the file extension before the scoring
*
* If param 'fileType' is given as string:
* Cutting the file extension given by this param
*
* @param sString1 - first string for comparison
* @param sString2 - second string for comparison
* @param params - object with attribute:
* 'extractKeywords' as parameter for extracting the keywords (true - extract keyword before calculating similarity score, false - whithout extraction)
* 'fileType' as parameter for the filetype of the file to cut the file extension
*/
function similarityPlugin (sString1, sString2, params) {
let extractKeywords = (params && params['extractKeywords']) || false

let fileType = (params && params['fileType']) || false

if ((typeof sString1 === 'undefined') || (typeof sString2 === 'undefined')) {
throw new Error(`Two Strings as input are needed.`)
}

utils.isValidString(sString1)
utils.isValidString(sString2)

if (fileType !== false) {
sString1 = utils.basename(sString1, fileType)
sString2 = utils.basename(sString2, fileType)
}

if (typeof extractKeywords !== 'boolean') {
throw new Error(`Boolean expected, found ${extractKeywords}`)
}
Expand Down
14 changes: 1 addition & 13 deletions lib/utils.js
@@ -1,15 +1,3 @@
/**
* Returns the basename without extension of filename. If the filename does not
* contain any dots it will be returned as is, otherwise the extension is
* stripped and the basename is returned.
*
* @param filename - name of a file basename.ext
*/
function basename (filename, filetype) {
let typePosition = filename.lastIndexOf('.' + filetype)
return typePosition === -1 ? filename : filename.substring(0, typePosition)
}

/**
* Returns a copy of the given object. The object must be serializable to
* JSON, thus cloning will only work on primitive objects.
Expand Down Expand Up @@ -63,4 +51,4 @@ function isTimestamp (timest) {
}
}

module.exports = { basename, cloneObject, isValidString, isInRange, isInteger, isTimestamp }
module.exports = { cloneObject, isValidString, isInRange, isInteger, isTimestamp }
20 changes: 4 additions & 16 deletions test/plugins/similar-context-test.js
Expand Up @@ -84,30 +84,18 @@ buster.testCase('similar-context-plugin', {
},

'should return 0.0 when there is no match at all ignoring the file extension': function () {
let file = { title: '123.jpeg' }
let file = { title: '123' }
let task = { title: 'location' }
let fileType = { fileType: 'jpeg' }

let result = plugin(file.title, task.title, fileType)
let result = plugin(file.title, task.title)
buster.assert.equals(result, 0.0)
},

'should return 1.0 when there is a total match ignoring the file extension': function () {
let file = { title: 'location.png' }
let file = { title: 'location' }
let task = { title: 'location' }
let fileType = { fileType: 'png' }

let result = plugin(file.title, task.title, fileType)
buster.assert.equals(result, 1.0)
},

'should return 1.0 when there is a total match ignoring the file extension': function () {
let file = { title: 'location.png' }
let task = { title: 'location' }
let fileType = { fileType: 'png' }

let result = plugin(file.title, task.title, fileType)
let result = plugin(file.title, task.title)
buster.assert.equals(result, 1.0)
}

})

0 comments on commit e26d8cd

Please sign in to comment.