-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up routing behaviour in ngram component #1727
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f3871ec
inherit StoreSync from ngram component
BeritJanssen 5c6c40f
fix: let ngramParameters inherit StoreSync
BeritJanssen 63500bb
chore: removed unused dependencies field-filter.spec
BeritJanssen ca6f59f
fix unit tests
BeritJanssen 792aabb
ngram component refinements
BeritJanssen b410da3
add unit test for ngramComponent.confirmChanges()
BeritJanssen cfaa837
fix intialization and destroy behaviour
BeritJanssen 4aa1f7e
fix: reorganize key retrieval for results cache
BeritJanssen 47a0060
remove date field from routing
BeritJanssen 9e68ccf
Merge branch 'develop' into feature/n-gram-update
BeritJanssen 66236de
fix: add dateField to resultsCache key
BeritJanssen 6bf5203
fix unit test
BeritJanssen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { SimpleStore } from '../store/simple-store'; | ||
import { RouterStoreService } from '../store/router-store.service'; | ||
import { NgramParameters, NgramSettings } from './ngram'; | ||
|
||
describe('NgramParameters', ()=> { | ||
let store: RouterStoreService = new SimpleStore() as any; | ||
let ngramParameters: NgramParameters; | ||
const testState = { | ||
size: 3, | ||
positions: 'first', | ||
freqCompensation: true, | ||
analysis: 'clean', | ||
maxDocuments: 100, | ||
numberOfNgrams: 20, | ||
} as NgramSettings; | ||
const testParams = {ngramSettings: 's:3,p:first,c:true,a:clean,m:100,n:20'} | ||
|
||
beforeEach(() => { | ||
ngramParameters = new NgramParameters(store); | ||
}); | ||
|
||
it('should correctly convert internal state to a route parameter', () => { | ||
const params = ngramParameters.stateToStore(testState); | ||
expect(params).toEqual(testParams); | ||
}); | ||
|
||
it('should correctly convert a route parameter to an internal state', () => { | ||
const state = ngramParameters.storeToState(testParams); | ||
expect(state).toEqual(testState); | ||
}); | ||
|
||
it('should return default values if no relevant route parameter is present', () => { | ||
const defaultSettings = { | ||
size: 2, | ||
positions: 'any', | ||
freqCompensation: false, | ||
analysis: 'none', | ||
maxDocuments: 50, | ||
numberOfNgrams: 10, | ||
} as NgramSettings; | ||
const state = ngramParameters.storeToState({irrelevant: 'parameter'}) | ||
expect(state).toEqual(defaultSettings); | ||
}) | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Params } from '@angular/router'; | ||
import * as _ from 'lodash'; | ||
|
||
import { StoreSync } from '../store/store-sync'; | ||
import { Store } from '../store/types'; | ||
|
||
export interface NgramSettings { | ||
size: number; | ||
positions: string; | ||
freqCompensation: boolean; | ||
analysis: string; | ||
maxDocuments: number; | ||
numberOfNgrams: number; | ||
} | ||
|
||
export class NgramParameters extends StoreSync<NgramSettings> { | ||
|
||
keysInStore = ['ngramSettings']; | ||
|
||
constructor(store: Store) { | ||
super(store); | ||
this.connectToStore(); | ||
} | ||
|
||
stringifyNgramSettings(state: NgramSettings): string { | ||
return [`s:${state.size}`,`p:${state.positions}`,`c:${state.freqCompensation}`, | ||
`a:${state.analysis}`,`m:${state.maxDocuments}`,`n:${state.numberOfNgrams}`].join(',') | ||
} | ||
|
||
stateToStore(state: NgramSettings): Params { | ||
return { ngramSettings: this.stringifyNgramSettings(state)} | ||
} | ||
|
||
storeToState(params: Params): NgramSettings { | ||
if (_.has(params, 'ngramSettings')) { | ||
const stringComponents = params['ngramSettings'].split(','); | ||
return { | ||
size: parseInt(this.findSetting('s', stringComponents), 10), | ||
positions: this.findSetting('p', stringComponents), | ||
freqCompensation: this.findSetting('c', stringComponents) === 'true', | ||
analysis: this.findSetting('a', stringComponents), | ||
maxDocuments: parseInt(this.findSetting('m', stringComponents), 10), | ||
numberOfNgrams: parseInt(this.findSetting('n', stringComponents), 10), | ||
} | ||
} | ||
return { | ||
size: 2, | ||
positions: 'any', | ||
freqCompensation: false, | ||
analysis: 'none', | ||
maxDocuments: 50, | ||
numberOfNgrams: 10, | ||
} as NgramSettings; | ||
} | ||
|
||
findSetting(abbreviation: string, stringComponents: string[]): string | undefined{ | ||
const setting = stringComponents.find(s => s[0] === abbreviation); | ||
return setting.split(':')[1]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change removes some unused imports, which I noticed when I was looking at other examples for testing routing behaviour.