Skip to content
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d03eaec
Renamed Profile to Procfile
Apr 7, 2017
aee1c1a
Adds more screenshot for wiki
Apr 7, 2017
3700ef6
Added test to coverall all files search and refactored class Inverted…
Apr 8, 2017
df12b74
Refactored the Inverted index class by removing unwanted part of the …
Apr 8, 2017
4f60e10
Updated the README file to include thelink to wiki
Apr 9, 2017
532e8ac
Adds codeclimate configuration file and modifies the application home…
Apr 9, 2017
d3f1837
Remove the default Procfile and App.json so the app can use the defau…
Apr 10, 2017
c759871
Updates the server.js to serve the index.html
Apr 10, 2017
d36cd89
Modified the server.js tp serve the javascript file
Apr 10, 2017
4d2a824
Modifies codeclimate configuration file
Apr 10, 2017
cc1d6d4
Updated codeclimate configuration file
Apr 10, 2017
741c47e
Updates the codeclimate config file to exclude images and jasmine dep…
Apr 10, 2017
816e73b
Adds test for words not found in search index and heroku app.json con…
Apr 10, 2017
d35e282
Modifies houndci configurations
Apr 10, 2017
d2ade4d
Renamed the eslint configuration file and modified the houndci config…
Apr 10, 2017
620a020
Adds test specs and inverted index class modified to correct houndci'…
Apr 10, 2017
20a1e60
renamed invertedindex.js to InvertedIndex.js using Pascal case and mo…
Apr 12, 2017
63f7b74
Corrected JSDOC comment for readfile method
Apr 12, 2017
a448fd7
Created bundle using browserify and modifies gulp to build on start
Apr 13, 2017
502afb9
Updates eslint config file, added browserify to bundle application, m…
Apr 13, 2017
77ba367
Refactored InvertedIndex class
Apr 15, 2017
226e490
Updates the JSDOC of the InvertedIndex class file
Apr 15, 2017
bb870c8
Refactored InvertedIndex class by modifying variable names
Apr 15, 2017
3693d9c
Modified the jasmine configuration file, changed the test specs filename
Apr 15, 2017
f440817
Modifies the eslint ignore config file
Apr 15, 2017
c6c7d88
Modifies InvertedIndex class and test spec to include changes like te…
Apr 17, 2017
de2d505
Modified InvertedIndex class and InvertedIndex test specs
Apr 17, 2017
b8b0720
Modifies InvertedIndex class
Apr 17, 2017
c128075
Modifies the InvertedIndex test spec
Apr 17, 2017
7011454
Updates InvertedIndex class and InvertedIndex test spec
Apr 18, 2017
0fd96e3
Controls table overflow, Corrects typo errors in test specs, includes…
Apr 18, 2017
435916b
updates coverall badge
Apr 18, 2017
b10f134
updated the readme file to reflect the new badge
Apr 18, 2017
6fca590
Updated the coverall badge
Apr 18, 2017
d586adf
Updates the InvertedIndex test spec
Apr 19, 2017
c3dc52b
Added InvertedIndex test spec
Apr 19, 2017
cc14b1e
Updated the test spec
Apr 19, 2017
3ed238c
Updated the InvertedIndex class test spec
Apr 19, 2017
8414503
Adds more sample books and modifies the InvertedIndex test spec
Apr 19, 2017
dd07287
Added Procfile and modified gitignore
Apr 19, 2017
f669ede
Added profile
Apr 19, 2017
9e83c02
Restructured files to correct heroku's application errors
Apr 19, 2017
b505061
Updated the index.html file
Apr 19, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
47 changes: 47 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
engines:
eslint:
enabled: true
duplication:
enabled: true
config:
languages:
- javascript
csslint:
enabled: false
# ... CONFIG CONTENT ...
checks:
comma-dangle:
enabled: false
import/no-unresolved:
enabled: false
no-console:
enabled: false
strict:
enabled: false
no-unused-vars:
enabled: false
no-undef:
enabled: false
class-methods-use-this:
enabled: false
no-param-reassign:
enabled: false
array-callback-return:
enabled: false
fixme:
enabled: true
ratings:
paths:
- "src/InvertedIndex.js"
exclude_paths:
- "samples/*"
- "*.json"
- "src/app.js"
- "src/module.js"
- "css/*"
- "index.html"
- "specs/*"
- .travis.yml
- .eslintrc.json
- "spec/*"
- "images/*"
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ spec/*.html
*.html
karma.conf.js
Profile
build/

3 changes: 1 addition & 2 deletions eslintrc.json → .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
},
"rules": {
"import/no-unresolved": 0,
"max-len":[2, 80, 2],
"one-var": 0,
"one-var-declaration-per-line": 0,
"new-cap": 0,
"no-undef": 0,
"func-names":0,
"consistent-return": 0,
"class-methods-use-this": 0,
"no-param-reassign": 0,
"no-prototype-builtins": 0,
"comma-dangle": 0,
"curly": [ 1, "multi-line" ],
"no-shadow": [ 1, { "allow": [ "req", "res", "err" ] } ],
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Coverage Status](https://coveralls.io/repos/github/andela-aonifade/dplex/badge.svg?branch=development)](https://coveralls.io/github/andela-aonifade/dplex?branch=development)
[![Coverage Status](https://s3.amazonaws.com/assets.coveralls.io/badges/coveralls_98.svg?branch=development)](https://coveralls.io/github/andela-aonifade/dplex?branch=development)
[![Code Climate](https://codeclimate.com/github/andela-aonifade/dplex/badges/gpa.svg)](https://codeclimate.com/github/andela-aonifade/dplex)
[![Build Status](https://travis-ci.org/andela-aonifade/dplex.svg?branch=development)](https://travis-ci.org/andela-aonifade/dplex)

Expand Down Expand Up @@ -40,5 +40,6 @@ It can also be used locally by following the steps below
- The application can not be distinguished between plural and singular words. It also does not distinguish between the past tense form of a verb. It does not identify synonyms and sees numbers as string

## More information
- [DPlex Wiki](https://github.com/andela-aonifade/dplex/wiki)
- [Inverted Index - Wikipedia](https://en.wikipedia.org/wiki/Inverted_index)
- [Inverted Index](https://www.elastic.co/guide/en/elasticsearch/guide/current/inverted-index.html)
303 changes: 303 additions & 0 deletions build/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the invocation into the parens that contain the function wrap-iife
A space is required after ',' comma-spacing
Requires a space after '{' block-spacing
Missing space before opening brace space-before-blocks
Missing JSDoc comment require-jsdoc
Expected space(s) after "if" keyword-spacing
Unexpected var, use let or const instead no-var
All 'var' declarations must be at the top of the function scope vars-on-top
Infix operators must be spaced space-infix-ops
Expected '===' and instead saw '==' eqeqeq
Strings must use singlequote quotes
Missing whitespace after semicolon semi-spacing
Expected space(s) before "return" keyword-spacing
'i' was used before it was defined no-use-before-define
Unexpected string concatenation prefer-template
Missing semicolon semi
Requires a space before '}' block-spacing
Expected space(s) before "var" keyword-spacing
A space is required after '{' object-curly-spacing
Missing space before value for key 'exports' key-spacing
A space is required before '}' object-curly-spacing
Unexpected function expression prefer-arrow-callback
Missing space before function parentheses space-before-function-paren
'e' is already declared in the upper scope no-shadow
'n' is already declared in the upper scope no-shadow
Unnecessary use of conditional expression for default assignment no-unneeded-ternary
Expected space(s) after "for" keyword-spacing
Unary operator '++' used no-plusplus
Missing space before value for key '1' key-spacing
'exports' is defined but never used no-unused-vars
Block must not be padded by blank lines padded-blocks

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the invocation into the parens that contain the function wrap-iife
Line 1 exceeds the maximum line length of 80 max-len
A space is required after ',' comma-spacing
Missing space before opening brace space-before-blocks
Requires a space after '{' block-spacing
Missing JSDoc comment require-jsdoc
Expected space(s) after "if" keyword-spacing
Unexpected var, use let or const instead no-var
All 'var' declarations must be at the top of the function scope vars-on-top
Infix operators must be spaced space-infix-ops
Expected '===' and instead saw '==' eqeqeq
Strings must use singlequote quotes
Missing whitespace after semicolon semi-spacing
Expected space(s) before "return" keyword-spacing
'i' was used before it was defined no-use-before-define
Unexpected string concatenation prefer-template
Missing semicolon semi
Requires a space before '}' block-spacing
Expected space(s) before "var" keyword-spacing
A space is required after '{' object-curly-spacing
Missing space before value for key 'exports' key-spacing
A space is required before '}' object-curly-spacing
Unexpected function expression prefer-arrow-callback
Missing space before function parentheses space-before-function-paren
'e' is already declared in the upper scope no-shadow
'n' is already declared in the upper scope no-shadow
Unnecessary use of conditional expression for default assignment no-unneeded-ternary
Expected space(s) after "for" keyword-spacing
Unary operator '++' used no-plusplus
Missing space before value for key '1' key-spacing
'exports' is defined but never used no-unused-vars
Block must not be padded by blank lines padded-blocks

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the invocation into the parens that contain the function wrap-iife
Line 1 exceeds the maximum line length of 80 max-len
A space is required after ',' comma-spacing
Missing space before opening brace space-before-blocks
Requires a space after '{' block-spacing
Missing JSDoc comment require-jsdoc
Expected space(s) after "if" keyword-spacing
All 'var' declarations must be at the top of the function scope vars-on-top
Unexpected var, use let or const instead no-var
Infix operators must be spaced space-infix-ops
Expected '===' and instead saw '==' eqeqeq
Strings must use singlequote quotes
Missing whitespace after semicolon semi-spacing
Expected space(s) before "return" keyword-spacing
'i' was used before it was defined no-use-before-define
Unexpected string concatenation prefer-template
Missing semicolon semi
Requires a space before '}' block-spacing
Expected space(s) before "var" keyword-spacing
A space is required after '{' object-curly-spacing
Missing space before value for key 'exports' key-spacing
A space is required before '}' object-curly-spacing
Unexpected function expression prefer-arrow-callback
Missing space before function parentheses space-before-function-paren
'e' is already declared in the upper scope no-shadow
'n' is already declared in the upper scope no-shadow
Unnecessary use of conditional expression for default assignment no-unneeded-ternary
Expected space(s) after "for" keyword-spacing
Unary operator '++' used no-plusplus
Missing space before value for key '1' key-spacing
'exports' is defined but never used no-unused-vars

module.exports=[

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 2 spaces but found 0 indent
Infix operators must be spaced space-infix-ops

{
"title": "Alice in Wonderland",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strings must use singlequote quotes
Unnecessarily quoted property 'title' found quote-props

"text": "Alice falls into a rabbit hole and enters a world full of imagination."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 5 exceeds the maximum line length of 80 max-len
Unnecessarily quoted property 'text' found quote-props
Strings must use singlequote quotes

},

{
"title": "The Lord of the Rings: The Fellowship of the Ring.",
"text": "An unusual alliance of man, elf, dwarf, wizard and hobbit seek to destroy a powerful ring."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 10 exceeds the maximum line length of 80 max-len
Strings must use singlequote quotes
Unnecessarily quoted property 'text' found quote-props

}
]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon semi


},{}],2:[function(require,module,exports){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block must not be padded by blank lines padded-blocks
A space is required after ',' comma-spacing
Object properties must go on a new line if they aren't all on the same line object-property-newline
Missing space before value for key '2' key-spacing
Missing space before function parentheses space-before-function-paren
'exports' is defined but never used no-unused-vars
Missing space before opening brace space-before-blocks

const validBookFile = require('../samples/books.json');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 2 spaces but found 0 indent


describe('InvertedIndex class', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 2 spaces but found 0 indent

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 2 spaces but found 0 indent

beforeAll(() => {
const indexInstance = new InvertedIndex();
const validBook = [{ title: 'Welcome to Test Environment',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'validBook' is assigned a value but never used no-unused-vars

text: 'Enjoy this file' }];
const books = [
{
title: 'Alice in Wonderland',
text:
'Alice falls into a rabbit hole and enters a world full of imagination.'
},

{
title: 'The Lord of the Rings: The Fellowship of the Ring.',
text: `An unusual alliance of man, elf, dwarf,
wizard and hobbit seek to destroy a powerful ring.`
},
{
title: 'The Lord of the Rings: The Fellowship of the Ring.',
text: `An unusual alliance of man, elf, dwarf,
wizard and hobbit seek to destroy a powerful ring.`
}
];
const anotherBook = [{
title: 'Alice the Great',
text:
'There is no better way to greatness than not giving up'
},

{
title: 'Are you there for Development',
text: `I have tried so many times but it's been unyielding
but I have made up my mind to develop no matter the obstacle`
}];
indexInstance.createIndex(books, 'books');
indexInstance.createIndex(anotherBook, 'anotherBook');
});
describe('InvertedIndex class', () => {
it('should check that the class has a createIndex method', () => {
expect(typeof indexInstance.createIndex).toBe('function');
});

it('should check that the class has a readFile method', () => {
expect(typeof InvertedIndex.readFile).toBe('function');
});

it('should check that the class has a validateFile method', () => {
expect(typeof InvertedIndex.validateFile).toBe('function');
});

it('should check that the class has a tokenize method', () => {
expect(typeof InvertedIndex.tokenize).toBe('function');
});

it('should check that the class has a getDocumentTokens method', () => {
expect(typeof InvertedIndex.getDocumentTokens).toBe('function');
});

it('should check that the class has a getIndex method', () => {
expect(typeof indexInstance.getIndex).toBe('function');
});

it('should check that the class has a searchIndex method', () => {
expect(typeof indexInstance.searchIndex).toBe('function');
});

it('should check that the class has a getSearchResults method', () => {
expect(typeof indexInstance.getSearchResults).toBe('function');
});

it('should check that the class has a getDocuments method', () => {
expect(typeof indexInstance.getDocuments).toBe('function');
});
});

describe('Read File', () => {
it('should return false for an invalid filename extension', () => {
const badFile = { name: 'badfileextension.jpg' };
const anotherBadFile = { name: 'badfileextension.jsona' };
InvertedIndex.readFile(badFile).then((response) => {
expect(response).toBeFalsy();
});
InvertedIndex.readFile(anotherBadFile).then((response) => {
expect(response).toBeFalsy();
});
});
const bookFile = new File([JSON.stringify(validBookFile)],
'books.json', { type: 'application/json' });
it('should return appropriate value for a valid json file', () => {
InvertedIndex.readFile(bookFile).then((response) => {
expect(response[0].title).toEqual(books[0].title);
});
});
});

describe('Create Index', () => {
it('should return mapped indices to words in a JSON file', () => {
const expectedResult =
{ alice: [0],
falls: [0],
into: [0],
a: [0, 1, 2],
rabbit: [0],
hole: [0],
and: [0, 1, 2],
enters: [0],
world: [0],
full: [0],
of: [0, 1, 2],
imagination: [0],
in: [0],
wonderland: [0],
an: [1, 2],
unusual: [1, 2],
alliance: [1, 2],
man: [1, 2],
elf: [1, 2],
dwarf: [1, 2],
wizard: [1, 2],
hobbit: [1, 2],
seek: [1, 2],
to: [1, 2],
destroy: [1, 2],
powerful: [1, 2],
ring: [1, 2],
the: [1, 2],
lord: [1, 2],
rings: [1, 2],
fellowship: [1, 2] };
expect(indexInstance.filesIndexed.books.index)
.toEqual(expectedResult);
});
it('should return false for file with no content', () => {
const term = {};
expect(indexInstance.createIndex(term, 'term')).toBeFalsy();
});
});
describe('Search Index', () => {
it('should search through single files that are indexed', () => {
const requiredOutput = { alice: [0],
and: [0, 1, 2],
unusual: [1, 2],
imagination: [0] };
const searchTerm = indexInstance
.searchIndex('Alice, and her unusual imagination', 'books');
expect(Object.keys(searchTerm[0].indexes))
.toEqual(Object.keys(requiredOutput));
expect(searchTerm[0].indexes).toEqual(requiredOutput);
});
it('should return false for an empty String', () => {
const term = '';
expect(indexInstance.searchIndex(term, 'books'))
.toBeFalsy();
});
it('should return an empty object for words not found', () => {
const term = 'Aeroplane';
const expectedOutput = indexInstance.searchIndex(term, 'books');
expect(expectedOutput[0].indexes).toEqual({ });
});
it('should return appropriate result for when all files is selected',
() => {
const expectedOutput =
[{ indexes: { alice: [0], the: [1, 2] },
searchedFile: 'books',
documents: [0, 1, 2] },
{ indexes: { alice: [0],
is: [0],
the: [0, 1] },
searchedFile: 'anotherBook',
documents: [0, 1] },
{ indexes: { },
searchedFile: 'term',
documents: [] }];
expect(indexInstance
.searchIndex('Alice is the', 'all')).toEqual(expectedOutput);
});
});

describe('Tokenize words', () => {
it('should strip out special characters from text in documents', () => {
let excerpt = 'Alice l##$oves her ima&&gination?';
const expectedTokens = ['alice', 'loves', 'her', 'imagination'];
excerpt = InvertedIndex.tokenize(excerpt);
expect(excerpt).toEqual(expectedTokens);
});
});

describe('Get index', () => {
it('should return the appropriate output for the given filename', () => {
const filename = 'books';
const expectedOutput = { alice: [0],
falls: [0],
into: [0],
a: [0, 1, 2],
rabbit: [0],
hole: [0],
and: [0, 1, 2],
enters: [0],
world: [0],
full: [0],
of: [0, 1, 2],
imagination: [0],
in: [0],
wonderland: [0],
an: [1, 2],
unusual: [1, 2],
alliance: [1, 2],
man: [1, 2],
elf: [1, 2],
dwarf: [1, 2],
wizard: [1, 2],
hobbit: [1, 2],
seek: [1, 2],
to: [1, 2],
destroy: [1, 2],
powerful: [1, 2],
ring: [1, 2],
the: [1, 2],
lord: [1, 2],
rings: [1, 2],
fellowship: [1, 2] };
expect(indexInstance.getIndex(filename))
.toEqual(expectedOutput);
});
it('should return false for an empty filename', () => {
const filename = '';
expect(indexInstance.getIndex(filename))
.toBeFalsy();
});
});

describe('Validate File', () => {
it('should return false for incorrect document structure', () => {
const term = [{ t1: 'Welcome home', text: 'This is really home' }];
expect(InvertedIndex.validateFile(term, 'term')).toBeFalsy();
});
it('should return true for correct document structure', () => {
const term = [{ title: 'Welcome home', text: 'This is really home' }];
expect(InvertedIndex.validateFile(term, 'term')).toBeTruthy();
});
});

describe('Get Document Tokens', () => {
it('should return the appropriate object for a given document',
() => {
const expectedOutput = { documentCount: 0,
textTokens: ['welcome', 'this', 'is', 'a', 'test', 'document'] };
const documentCount = 0;
const term = [{ text: 'Welcome', title: 'This is a test document' }];
expect(InvertedIndex
.getDocumentTokens(term, documentCount)).toEqual(expectedOutput);
});
});

describe('Get Document Data', () => {
it('should return the appropriate array of documents for a given file',
() => {
const expectedOutput = [0, 1, 2];
expect(indexInstance
.getDocuments('books')).toEqual(expectedOutput);
});
});

describe('Get Search result Data', () => {
it('should return the appropriate result for tokens searched',
() => {
const words = 'Alice is a girl';
const expectedOutput = { alice: [0], a: [0, 1, 2] };
expect(indexInstance
.getSearchResults(words, 'books')).toEqual(expectedOutput);
});
});

describe('Get Construct Index Data', () => {
it('should return the appropriate indexed words for a given document',
() => {
const documentTokens = [{ documentCount: 0,
textTokens: ['welcome', 'this', 'is', 'a', 'test', 'document'] }];
const expectedOutput =
{ welcome: [0], this: [0], is: [0], a: [0], test: [0], document: [0] };
expect(InvertedIndex.constructIndex(documentTokens))
.toEqual(expectedOutput);
});
});
});

},{"../samples/books.json":1}]},{},[2])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block must not be padded by blank lines padded-blocks
A space is required after ',' comma-spacing
A space is required after '{' object-curly-spacing
Strings must use singlequote quotes
Missing space before value for key '../samples/books.json' key-spacing
A space is required before '}' object-curly-spacing
Missing semicolon semi
Newline required at end of file but not found eol-last

5 changes: 5 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@
.padding10{
padding: 10px;
}

#myTable{
z-index: 1;
overflow-y: scroll;
}
Loading