2022-07-13 12:06:22 +00:00
class ConcordanceQueryBuilder {
2022-09-07 07:06:21 +00:00
constructor ( ) {
2022-08-03 14:21:11 +00:00
2022-07-13 12:06:22 +00:00
2022-09-07 07:06:21 +00:00
this . elements = {
counter : 0 ,
yourQueryContent : [ ] ,
queryContent : [ ] ,
2022-10-12 12:08:42 +00:00
concordanceQueryBuilder : document . querySelector ( '#concordance-query-builder' ) ,
concordanceQueryBuilderButton : document . querySelector ( '#concordance-query-builder-button' ) ,
closeQueryBuilder : document . querySelector ( '#close-query-builder' ) ,
2022-09-07 07:06:21 +00:00
queryBuilderTutorialModal : document . querySelector ( '#query-builder-tutorial-modal' ) ,
2022-10-20 13:52:25 +00:00
valueValidator : true ,
2022-09-07 07:06:21 +00:00
//#region QueryBuilder Elements
positionalAttrButton : document . querySelector ( '#positional-attr-button' ) ,
positionalAttrArea : document . querySelector ( '#positional-attr' ) ,
2022-10-12 12:08:42 +00:00
positionalAttr : document . querySelector ( '#token-attr' ) ,
2022-09-07 07:06:21 +00:00
structuralAttrButton : document . querySelector ( '#structural-attr-button' ) ,
2022-10-12 12:08:42 +00:00
structuralAttrArea : document . querySelector ( '#structural-attr' ) ,
2022-09-07 07:06:21 +00:00
queryContainer : document . querySelector ( '#query-container' ) ,
2022-10-12 12:08:42 +00:00
buttonPreparer : document . querySelector ( '#button-preparer' ) ,
yourQuery : document . querySelector ( '#your-query' ) ,
insertQueryButton : document . querySelector ( '#insert-query-button' ) ,
2022-09-07 07:06:21 +00:00
queryPreview : document . querySelector ( '#query-preview' ) ,
2022-10-12 12:08:42 +00:00
tokenQuery : document . querySelector ( '#token-query' ) ,
tokenBuilderContent : document . querySelector ( '#token-builder-content' ) ,
tokenSubmitButton : document . querySelector ( '#token-submit' ) ,
2022-09-07 07:06:21 +00:00
extFormQuery : document . querySelector ( '#concordance-extension-form-query' ) ,
2022-10-12 12:08:42 +00:00
dropButton : '' ,
2022-09-07 07:06:21 +00:00
queryBuilderTutorialInfoIcon : document . querySelector ( '#query-builder-tutorial-info-icon' ) ,
2022-10-12 12:08:42 +00:00
tokenTutorialInfoIcon : document . querySelector ( '#token-tutorial-info-icon' ) ,
2022-09-07 07:06:21 +00:00
editTokenTutorialInfoIcon : document . querySelector ( '#edit-options-tutorial-info-icon' ) ,
structuralAttributeTutorialInfoIcon : document . querySelector ( '#add-structural-attribute-tutorial-info-icon' ) ,
generalOptionsQueryBuilderTutorialInfoIcon : document . querySelector ( '#general-options-query-builder-tutorial-info-icon' ) ,
2022-07-13 12:06:22 +00:00
2022-09-07 07:06:21 +00:00
//#endregion QueryBuilder Elements
2022-07-13 12:06:22 +00:00
2022-09-07 07:06:21 +00:00
//#region Strucutral Attributes
2022-07-13 12:06:22 +00:00
2022-10-12 12:08:42 +00:00
sentence : document . querySelector ( '#sentence' ) ,
entity : document . querySelector ( '#entity' ) ,
textAnnotation : document . querySelector ( '#text-annotation' ) ,
entityBuilder : document . querySelector ( '#entity-builder' ) ,
englishEntType : document . querySelector ( '#english-ent-type' ) ,
germanEntType : document . querySelector ( '#german-ent-type' ) ,
emptyEntity : document . querySelector ( '#empty-entity' ) ,
2022-09-07 07:06:21 +00:00
entityAnyType : false ,
2022-10-12 12:08:42 +00:00
textAnnotationBuilder : document . querySelector ( '#text-annotation-builder' ) ,
textAnnotationOptions : document . querySelector ( '#text-annotation-options' ) ,
textAnnotationInput : document . querySelector ( '#text-annotation-input' ) ,
textAnnotationSubmit : document . querySelector ( '#text-annotation-submit' ) ,
2022-09-07 07:06:21 +00:00
noValueMetadataMessage : document . querySelector ( '#no-value-metadata-message' ) ,
//#endregion Structural Attributes
//#region Token Attributes
tokenQueryFilled : false ,
2022-10-12 12:08:42 +00:00
lemma : document . querySelector ( '#lemma' ) ,
emptyToken : document . querySelector ( '#empty-token' ) ,
word : document . querySelector ( '#word' ) ,
lemma : document . querySelector ( '#lemma' ) ,
pos : document . querySelector ( '#pos' ) ,
simplePosButton : document . querySelector ( '#simple-pos-button' ) ,
incidenceModifiers : document . querySelector ( '[data-target="incidence-modifiers"]' ) ,
or : document . querySelector ( '#or' ) ,
and : document . querySelector ( '#and' ) ,
2022-09-07 07:06:21 +00:00
//#region Word and Lemma Elements
2022-10-12 12:08:42 +00:00
wordBuilder : document . querySelector ( '#word-builder' ) ,
lemmaBuilder : document . querySelector ( '#lemma-builder' ) ,
inputOptions : document . querySelector ( '#input-options' ) ,
incidenceModifiersButton : document . querySelector ( '#incidence-modifiers-button' ) ,
2022-09-07 07:06:21 +00:00
conditionContainer : document . querySelector ( '#condition-container' ) ,
2022-10-12 12:08:42 +00:00
wordInput : document . querySelector ( '#word-input' ) ,
lemmaInput : document . querySelector ( '#lemma-input' ) ,
ignoreCaseCheckbox : document . querySelector ( '#ignore-case-checkbox' ) ,
ignoreCase : document . querySelector ( 'input[type="checkbox"]' ) ,
wildcardChar : document . querySelector ( '#wildcard-char' ) ,
optionGroup : document . querySelector ( '#option-group' ) ,
2022-09-07 07:06:21 +00:00
//#endregion Word and Lemma Elements
//#region posBuilder Elements
2022-10-12 12:08:42 +00:00
englishPosBuilder : document . querySelector ( '#english-pos-builder' ) ,
englishPos : document . querySelector ( '#english-pos' ) ,
germanPosBuilder : document . querySelector ( '#german-pos-builder' ) ,
germanPos : document . querySelector ( '#german-pos' ) ,
2022-09-07 07:06:21 +00:00
//#endregion posBuilder Elements
//#region simple_posBuilder Elements
2022-10-12 12:08:42 +00:00
simplePosBuilder : document . querySelector ( '#simplepos-builder' ) ,
simplePos : document . querySelector ( '#simple-pos' ) ,
2022-09-07 07:06:21 +00:00
//#endregion simple_posBuilder Elements
//#region incidence modifiers
2022-10-12 12:08:42 +00:00
oneOrMore : document . querySelector ( '#one-or-more' ) ,
zeroOrMore : document . querySelector ( '#zero-or-more' ) ,
zeroOrOne : document . querySelector ( '#zero-or-one' ) ,
exactlyN : document . querySelector ( '#exactlyN' ) ,
betweenNM : document . querySelector ( '#betweenNM' ) ,
nInput : document . querySelector ( '#n-input' ) ,
nSubmit : document . querySelector ( '#n-submit' ) ,
nmInput : document . querySelector ( '#n-m-input' ) ,
mInput : document . querySelector ( '#m-input' ) ,
nmSubmit : document . querySelector ( '#n-m-submit' ) ,
2022-09-07 07:06:21 +00:00
//#endregion incidence modifiers
cancelBool : false ,
noValueMessage : document . querySelector ( '#no-value-message' ) ,
//#endregion Token Attributes
}
2022-07-13 12:06:22 +00:00
2022-10-12 12:08:42 +00:00
this . elements . closeQueryBuilder . addEventListener ( 'click' , ( ) => { this . closeQueryBuilderModal ( this . elements . concordanceQueryBuilder ) ; } ) ;
this . elements . concordanceQueryBuilderButton . addEventListener ( 'click' , ( ) => { this . clearAll ( ) ; } ) ;
this . elements . insertQueryButton . addEventListener ( 'click' , ( ) => { this . insertQuery ( ) ; } ) ;
this . elements . positionalAttrButton . addEventListener ( 'click' , ( ) => { this . showPositionalAttrArea ( ) ; } ) ;
this . elements . structuralAttrButton . addEventListener ( 'click' , ( ) => { this . showStructuralAttrArea ( ) ; } ) ;
2022-09-07 07:06:21 +00:00
//#region Structural Attribute Event Listeners
2022-10-12 12:08:42 +00:00
this . elements . sentence . addEventListener ( 'click' , ( ) => { this . addSentence ( ) ; } ) ;
this . elements . entity . addEventListener ( 'click' , ( ) => { this . addEntity ( ) ; } ) ;
this . elements . textAnnotation . addEventListener ( 'click' , ( ) => { this . addTextAnnotation ( ) ; } ) ;
2022-09-07 07:06:21 +00:00
2022-10-12 12:08:42 +00:00
this . elements . englishEntType . addEventListener ( 'change' , ( ) => { this . englishEntTypeHandler ( ) ; } ) ;
this . elements . germanEntType . addEventListener ( 'change' , ( ) => { this . germanEntTypeHandler ( ) ; } ) ;
this . elements . emptyEntity . addEventListener ( 'click' , ( ) => { this . emptyEntityButton ( ) ; } ) ;
2022-07-13 12:06:22 +00:00
2022-10-12 12:08:42 +00:00
this . elements . textAnnotationSubmit . addEventListener ( 'click' , ( ) => { this . textAnnotationSubmitHandler ( ) ; } ) ;
2022-07-13 12:06:22 +00:00
2022-09-07 07:06:21 +00:00
//#endregion
2022-07-13 12:06:22 +00:00
2022-09-07 07:06:21 +00:00
//#region Token Attribute Event Listeners
2022-10-12 12:08:42 +00:00
this . elements . queryBuilderTutorialInfoIcon . addEventListener ( 'click' , ( ) => { this . tutorialIconHandler ( '#query-builder-tutorial-start' ) ; } ) ;
this . elements . tokenTutorialInfoIcon . addEventListener ( 'click' , ( ) => { this . tutorialIconHandler ( '#add-new-token-tutorial' ) ; } ) ;
this . elements . editTokenTutorialInfoIcon . addEventListener ( 'click' , ( ) => { this . tutorialIconHandler ( '#edit-options-tutorial' ) ; } ) ;
this . elements . structuralAttributeTutorialInfoIcon . addEventListener ( 'click' , ( ) => { this . tutorialIconHandler ( '#add-structural-attribute-tutorial' ) ; } ) ;
this . elements . generalOptionsQueryBuilderTutorialInfoIcon . addEventListener ( 'click' , ( ) => { this . tutorialIconHandler ( '#general-options-query-builder' ) ; } ) ;
2022-09-07 07:06:21 +00:00
2022-10-12 12:08:42 +00:00
this . elements . positionalAttr . addEventListener ( 'change' , ( ) => { this . tokenTypeSelector ( ) ; } ) ;
this . elements . tokenSubmitButton . addEventListener ( 'click' , ( ) => { this . addToken ( ) ; } ) ;
2022-09-07 07:06:21 +00:00
2022-10-12 12:08:42 +00:00
this . elements . ignoreCase . addEventListener ( 'change' , ( ) => { this . inputOptionHandler ( this . elements . ignoreCase ) ; } ) ;
this . elements . wildcardChar . addEventListener ( 'click' , ( ) => { this . inputOptionHandler ( this . elements . wildcardChar ) ; } ) ;
this . elements . optionGroup . addEventListener ( 'click' , ( ) => { this . inputOptionHandler ( this . elements . optionGroup ) ; } ) ;
2022-09-07 07:06:21 +00:00
2022-10-12 12:08:42 +00:00
this . elements . oneOrMore . addEventListener ( 'click' , ( ) => { this . incidenceModifiersHandler ( this . elements . oneOrMore ) ; } ) ;
this . elements . zeroOrMore . addEventListener ( 'click' , ( ) => { this . incidenceModifiersHandler ( this . elements . zeroOrMore ) ; } ) ;
this . elements . zeroOrOne . addEventListener ( 'click' , ( ) => { this . incidenceModifiersHandler ( this . elements . zeroOrOne ) ; } ) ;
this . elements . nSubmit . addEventListener ( 'click' , ( ) => { this . nSubmitHandler ( ) ; } ) ;
this . elements . nmSubmit . addEventListener ( 'click' , ( ) => { this . nmSubmitHandler ( ) ; } ) ;
2022-09-07 07:06:21 +00:00
2022-10-12 12:08:42 +00:00
this . elements . or . addEventListener ( 'click' , ( ) => { this . orHandler ( ) ; } ) ;
this . elements . and . addEventListener ( 'click' , ( ) => { this . andHandler ( ) ; } ) ;
2022-09-07 07:06:21 +00:00
//#endregion Token Attribute Event Listeners
}
2022-10-12 12:05:01 +00:00
// ##########################################################################
// #################### General Functions ###################################
// ##########################################################################
2022-09-07 07:06:21 +00:00
//#region General Functions
2022-10-12 12:05:01 +00:00
closeQueryBuilderModal ( closeInstance ) {
2022-09-07 07:06:21 +00:00
let instance = M . Modal . getInstance ( closeInstance ) ;
instance . close ( ) ;
}
2022-10-12 12:05:01 +00:00
showPositionalAttrArea ( ) {
2022-09-07 07:06:21 +00:00
this . elements . positionalAttrArea . classList . remove ( 'hide' ) ;
2022-10-12 12:08:42 +00:00
this . elements . wordBuilder . classList . remove ( 'hide' ) ;
this . elements . inputOptions . classList . remove ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
this . elements . incidenceModifiersButton . classList . remove ( 'hide' ) ;
2022-10-12 12:08:42 +00:00
this . elements . conditionContainer . classList . remove ( 'hide' ) ;
this . elements . ignoreCaseCheckbox . classList . remove ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
this . elements . structuralAttrArea . classList . add ( 'hide' ) ;
this . elements . lemmaBuilder . classList . add ( 'hide' ) ;
this . elements . englishPosBuilder . classList . add ( 'hide' ) ;
this . elements . germanPosBuilder . classList . add ( 'hide' ) ;
this . elements . simplePosBuilder . classList . add ( 'hide' ) ;
this . elements . tokenQueryFilled = false ;
2022-10-12 12:08:42 +00:00
window . location . href = '#token-builder-content' ;
2022-09-07 07:06:21 +00:00
// Resets materialize select field to default value
let SelectInstance = M . FormSelect . getInstance ( this . elements . positionalAttr ) ;
2022-10-12 12:08:42 +00:00
SelectInstance . input . value = 'word' ;
this . elements . positionalAttr . value = 'word' ;
2022-09-07 07:06:21 +00:00
}
2022-10-12 12:05:01 +00:00
showStructuralAttrArea ( ) {
2022-09-07 07:06:21 +00:00
this . elements . positionalAttrArea . classList . add ( 'hide' ) ;
this . elements . structuralAttrArea . classList . remove ( 'hide' ) ;
}
buttonfactory ( dataType , prettyText , queryText ) {
2022-10-12 12:08:42 +00:00
window . location . href = '#query-container' ;
2022-09-07 07:06:21 +00:00
this . elements . counter += 1 ;
queryText = encodeURI ( queryText ) ;
2022-10-13 13:15:53 +00:00
let buttonElement = Utils . elementFromString (
`
< div class = 'chip' data - type = '${dataType}' data - query = '${queryText}' draggable = 'true' style = 'cursor:pointer;' ondragstart = 'concordanceQueryBuilder.dragStartHandler(event)' ondragend = 'concordanceQueryBuilder.dragEndHandler(event)' >
$ { prettyText }
< i class = 'material-icons close' > close < / i >
< / d i v >
`
) ;
2022-10-12 12:08:42 +00:00
buttonElement . addEventListener ( 'click' , ( ) => { this . deleteAttr ( buttonElement ) ; } ) ;
2022-09-07 07:06:21 +00:00
// Ensures that metadata is always at the end of the query:
2022-10-12 12:08:42 +00:00
if ( this . elements . yourQuery . lastChild === null || this . elements . yourQuery . lastChild . dataset . type !== 'text-annotation' ) {
2022-09-07 07:06:21 +00:00
this . elements . yourQuery . appendChild ( buttonElement ) ;
2022-10-12 12:08:42 +00:00
} else if ( this . elements . yourQuery . lastChild . dataset . type === 'text-annotation' ) {
2022-09-07 07:06:21 +00:00
this . elements . yourQuery . insertBefore ( buttonElement , this . elements . yourQuery . lastChild ) ;
}
2022-10-12 12:08:42 +00:00
this . elements . queryContainer . classList . remove ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
this . queryPreviewBuilder ( ) ;
// Opens a hint about the possible functions for editing the query when the first chip is added. It is displayed for 5 seconds and then deleted.
2022-10-12 12:08:42 +00:00
if ( this . elements . yourQuery . classList . contains ( 'tooltipped' ) ) {
2022-09-07 07:06:21 +00:00
let tooltipInstance = M . Tooltip . getInstance ( this . elements . yourQuery ) ;
2022-10-12 12:08:42 +00:00
tooltipInstance . tooltipEl . style . background = '#98ACD2' ;
tooltipInstance . tooltipEl . style . borderTop = 'solid 4px #0064A3'
tooltipInstance . tooltipEl . style . padding = '10px' ;
tooltipInstance . tooltipEl . style . color = 'black' ;
2022-09-07 07:06:21 +00:00
2022-10-12 12:05:01 +00:00
if ( tooltipInstance !== undefined ) {
2022-09-07 07:06:21 +00:00
setTimeout ( ( ) => {
tooltipInstance . open ( ) ;
setTimeout ( ( ) => {
tooltipInstance . destroy ( ) ;
} , 5000 ) ;
} , 500 ) ;
}
2022-10-12 12:08:42 +00:00
this . elements . yourQuery . classList . remove ( 'tooltipped' ) ;
2022-09-07 07:06:21 +00:00
}
}
2022-10-12 12:05:01 +00:00
//#region Drag&Drop Events
dragStartHandler ( event ) {
2022-10-20 13:52:25 +00:00
// Creates element with the class 'target' and all necessary drop functions, in which drop content can be released
2022-09-07 07:06:21 +00:00
this . elements . dropButton = event . target ;
let targetChip = `
2022-10-12 12:08:42 +00:00
< div class = 'chip target' ondragover = 'concordanceQueryBuilder.dragOverHandler(event)' ondragenter = 'concordanceQueryBuilder.dragEnterHandler(event)' ondragleave = 'concordanceQueryBuilder.dragLeaveHandler(event)' ondrop = 'concordanceQueryBuilder.dropHandler(event)' >
2022-10-12 12:05:01 +00:00
Drop here
< / d i v >
2022-09-07 07:06:21 +00:00
` .trim();
2022-10-20 13:52:25 +00:00
// selects all nodes without target class
2022-10-12 12:08:42 +00:00
let childNodes = this . elements . yourQuery . querySelectorAll ( 'div:not(.target)' ) ;
2022-09-07 07:06:21 +00:00
2022-10-20 13:52:25 +00:00
// Adds a target chip in front of all draggable childnodes
2022-09-07 07:06:21 +00:00
setTimeout ( ( ) => {
2022-10-12 12:05:01 +00:00
for ( let element of childNodes ) {
2022-10-20 13:52:25 +00:00
if ( element === this . elements . dropButton ) {
// If the dragged element is not at the very end, a target chip is also inserted at the end
if ( childNodes [ childNodes . length - 1 ] !== element ) {
childNodes [ childNodes . length - 1 ] . insertAdjacentHTML ( 'afterend' , targetChip ) ;
}
} else if ( element === this . elements . dropButton . nextSibling ) {
2022-09-07 07:06:21 +00:00
continue ;
2022-10-12 12:05:01 +00:00
} else {
2022-10-12 12:08:42 +00:00
element . insertAdjacentHTML ( 'beforebegin' , targetChip )
2022-07-13 12:06:22 +00:00
}
2022-09-07 07:06:21 +00:00
}
} , 0 ) ;
}
2022-07-13 12:06:22 +00:00
2022-10-12 12:05:01 +00:00
dragOverHandler ( event ) {
2022-09-07 07:06:21 +00:00
event . preventDefault ( ) ;
}
2022-07-13 12:06:22 +00:00
2022-10-12 12:05:01 +00:00
dragEnterHandler ( event ) {
2022-09-07 07:06:21 +00:00
event . preventDefault ( ) ;
2022-10-12 12:08:42 +00:00
event . target . style . borderStyle = 'solid dotted' ;
2022-09-07 07:06:21 +00:00
}
2022-07-13 12:06:22 +00:00
2022-10-12 12:05:01 +00:00
dragLeaveHandler ( event ) {
2022-09-07 07:06:21 +00:00
event . preventDefault ( ) ;
2022-10-12 12:08:42 +00:00
event . target . style . borderStyle = 'hidden' ;
2022-09-07 07:06:21 +00:00
}
2022-07-13 12:06:22 +00:00
2022-10-12 12:05:01 +00:00
dragEndHandler ( event ) {
2022-09-07 07:06:21 +00:00
let targets = document . querySelectorAll ( '.target' ) ;
2022-10-12 12:05:01 +00:00
for ( let target of targets ) {
2022-09-07 07:06:21 +00:00
target . remove ( ) ;
2022-07-13 12:06:22 +00:00
}
2022-09-07 07:06:21 +00:00
}
2022-07-13 12:06:22 +00:00
2022-10-12 12:05:01 +00:00
dropHandler ( event ) {
2022-09-07 07:06:21 +00:00
let dropzone = event . target ;
dropzone . parentElement . replaceChild ( this . elements . dropButton , dropzone ) ;
this . queryPreviewBuilder ( ) ;
}
2022-09-07 12:47:42 +00:00
//#endregion Drag&Drop Events
2022-08-01 08:00:12 +00:00
2022-10-12 12:05:01 +00:00
queryPreviewBuilder ( ) {
2022-09-07 07:06:21 +00:00
this . elements . yourQueryContent = [ ] ;
for ( let element of this . elements . yourQuery . childNodes ) {
let queryElement = decodeURI ( element . dataset . query ) ;
2022-10-12 12:08:42 +00:00
if ( queryElement . includes ( '<' ) ) {
queryElement = queryElement . replace ( '<' , '<' ) ;
2022-09-07 07:06:21 +00:00
}
2022-10-12 12:08:42 +00:00
if ( queryElement . includes ( '>' ) ) {
queryElement = queryElement . replace ( '>' , '>' ) ;
2022-09-07 07:06:21 +00:00
}
2022-10-12 12:08:42 +00:00
if ( queryElement !== 'undefined' ) {
2022-09-07 07:06:21 +00:00
this . elements . yourQueryContent . push ( queryElement ) ;
}
2022-08-01 08:00:12 +00:00
}
2022-07-13 12:06:22 +00:00
2022-09-07 07:06:21 +00:00
let queryString = this . elements . yourQueryContent . join ( ' ' ) ;
2022-10-12 12:08:42 +00:00
queryString += ';' ;
2022-09-07 07:06:21 +00:00
this . elements . queryPreview . innerHTML = queryString ;
}
2022-07-13 12:06:22 +00:00
2022-08-01 08:00:12 +00:00
2022-09-07 07:06:21 +00:00
deleteAttr ( attr ) {
this . elements . yourQuery . removeChild ( attr ) ;
2022-07-13 12:06:22 +00:00
2022-09-07 07:06:21 +00:00
this . elements . counter -= 1 ;
2022-10-12 12:05:01 +00:00
if ( this . elements . counter === 0 ) {
2022-10-12 12:08:42 +00:00
this . elements . queryContainer . classList . add ( 'hide' ) ;
2022-07-13 12:06:22 +00:00
}
2022-09-07 07:06:21 +00:00
this . queryPreviewBuilder ( ) ;
}
2022-07-13 12:06:22 +00:00
2022-09-07 07:06:21 +00:00
insertQuery ( ) {
this . elements . yourQueryContent = [ ] ;
2022-10-20 13:52:25 +00:00
this . validateValue ( ) ;
if ( this . elements . valueValidator === true ) {
for ( let element of this . elements . yourQuery . childNodes ) {
let queryElement = decodeURI ( element . dataset . query ) ;
if ( queryElement !== 'undefined' ) {
this . elements . yourQueryContent . push ( queryElement ) ;
}
}
let queryString = this . elements . yourQueryContent . join ( ' ' ) ;
queryString += ';' ;
2022-08-01 08:00:12 +00:00
2022-10-20 13:52:25 +00:00
this . elements . concordanceQueryBuilder . classList . add ( 'modal-close' ) ;
this . elements . extFormQuery . value = queryString ;
}
}
validateValue ( ) {
this . elements . valueValidator = true ;
let sentenceCounter = 0 ;
let sentenceEndCounter = 0 ;
let entityCounter = 0 ;
let entityEndCounter = 0 ;
2022-09-07 07:06:21 +00:00
for ( let element of this . elements . yourQuery . childNodes ) {
2022-10-20 13:52:25 +00:00
if ( element . dataset . type === 'start-sentence' ) {
sentenceCounter += 1 ;
} else if ( element . dataset . type === 'end-sentence' ) {
sentenceEndCounter += 1 ;
} else if ( element . dataset . type === 'start-entity' || element . dataset . type === 'start-empty-entity' ) {
entityCounter += 1 ;
} else if ( element . dataset . type === 'end-entity' ) {
entityEndCounter += 1 ;
2022-10-12 12:05:01 +00:00
}
2022-07-13 12:06:22 +00:00
}
2022-10-20 13:52:25 +00:00
if ( sentenceCounter !== sentenceEndCounter ) {
app . flash ( 'Please add a closing sentence tag' , 'error' ) ;
this . elements . valueValidator = false ;
}
if ( entityCounter !== entityEndCounter ) {
app . flash ( 'Please add a closing entity tag' , 'error' ) ;
this . elements . valueValidator = false ;
}
2022-09-07 07:06:21 +00:00
}
2022-07-13 12:06:22 +00:00
2022-09-07 07:06:21 +00:00
clearAll ( ) {
2022-10-12 12:08:42 +00:00
// Everything is reset. After 5 seconds for 5 seconds (with 'instance'), a message is displayed indicating that further information can be obtained via the question mark icon
2022-09-07 07:06:21 +00:00
let instance = M . Tooltip . getInstance ( this . elements . queryBuilderTutorialInfoIcon ) ;
2022-07-13 12:06:22 +00:00
2022-09-07 07:06:21 +00:00
this . hideEverything ( ) ;
this . elements . counter = 0 ;
this . elements . concordanceQueryBuilder . classList . remove ( 'modal-close' ) ;
this . elements . positionalAttrArea . classList . add ( 'hide' ) ;
this . elements . structuralAttrArea . classList . add ( 'hide' ) ;
this . elements . yourQuery . innerHTML = '' ;
this . elements . queryContainer . classList . add ( 'hide' ) ;
instance . tooltipEl . style . background = '#98ACD2' ;
instance . tooltipEl . style . borderTop = 'solid 4px #0064A3' ;
instance . tooltipEl . style . padding = '10px' ;
instance . tooltipEl . style . color = 'black' ;
setTimeout ( ( ) => {
instance . open ( ) ;
setTimeout ( ( ) => {
2022-08-03 14:21:11 +00:00
instance . close ( ) ;
2022-09-07 07:06:21 +00:00
} , 5000 ) ;
} , 5000 ) ;
}
tutorialIconHandler ( id ) {
setTimeout ( ( ) => {
window . location . href = id ;
} , 0 ) ;
}
//#endregion General Functions
2022-10-12 12:05:01 +00:00
// ##########################################################################
// ############## Token Attribute Builder Functions #########################
// ##########################################################################
2022-09-07 07:06:21 +00:00
//#region Token Attribute Builder Functions
//#region General functions of the Token Builder
tokenTypeSelector ( ) {
this . hideEverything ( ) ;
switch ( this . elements . positionalAttr . value ) {
2022-10-12 12:08:42 +00:00
case 'word' :
2022-09-07 07:06:21 +00:00
this . wordBuilder ( ) ;
break ;
2022-10-12 12:08:42 +00:00
case 'lemma' :
2022-09-07 07:06:21 +00:00
this . lemmaBuilder ( ) ;
break ;
2022-10-12 12:08:42 +00:00
case 'english-pos' :
2022-09-07 07:06:21 +00:00
this . englishPosHandler ( ) ;
break ;
2022-10-12 12:08:42 +00:00
case 'german-pos' :
2022-09-07 07:06:21 +00:00
this . germanPosHandler ( ) ;
break ;
2022-10-12 12:08:42 +00:00
case 'simple-pos-button' :
2022-09-07 07:06:21 +00:00
this . simplePosBuilder ( ) ;
break ;
2022-10-12 12:08:42 +00:00
case 'empty-token' :
2022-09-07 07:06:21 +00:00
this . emptyTokenHandler ( ) ;
break ;
default :
this . wordBuilder ( ) ;
break ;
}
}
2022-10-12 12:05:01 +00:00
hideEverything ( ) {
2022-09-07 07:06:21 +00:00
2022-10-12 12:08:42 +00:00
this . elements . wordBuilder . classList . add ( 'hide' ) ;
this . elements . lemmaBuilder . classList . add ( 'hide' ) ;
this . elements . ignoreCaseCheckbox . classList . add ( 'hide' ) ;
this . elements . inputOptions . classList . add ( 'hide' ) ;
this . elements . incidenceModifiersButton . classList . add ( 'hide' ) ;
this . elements . conditionContainer . classList . add ( 'hide' ) ;
this . elements . englishPosBuilder . classList . add ( 'hide' ) ;
this . elements . germanPosBuilder . classList . add ( 'hide' ) ;
this . elements . simplePosBuilder . classList . add ( 'hide' ) ;
this . elements . entityBuilder . classList . add ( 'hide' ) ;
this . elements . textAnnotationBuilder . classList . add ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
}
tokenButtonfactory ( prettyText , tokenText ) {
tokenText = encodeURI ( tokenText ) ;
let builderElement ;
let buttonElement ;
builderElement = document . createElement ( 'div' ) ;
builderElement . innerHTML = `
2022-10-12 12:08:42 +00:00
< div class = 'chip col s2 l2' style = 'margin-top:20px;' data - tokentext = '${tokenText}' >
2022-09-07 07:06:21 +00:00
$ { prettyText }
2022-10-12 12:08:42 +00:00
< i class = 'material-icons close' > close < / i >
2022-09-07 07:06:21 +00:00
< / d i v > ` ;
buttonElement = builderElement . firstElementChild ;
2022-10-12 12:08:42 +00:00
buttonElement . addEventListener ( 'click' , ( ) => { this . deleteTokenAttr ( buttonElement ) ; } ) ;
2022-09-07 07:06:21 +00:00
this . elements . tokenQuery . appendChild ( buttonElement ) ;
}
2022-10-12 12:05:01 +00:00
deleteTokenAttr ( attr ) {
2022-09-07 07:06:21 +00:00
if ( this . elements . tokenQuery . childNodes . length < 2 ) {
this . elements . tokenQuery . removeChild ( attr ) ;
this . wordBuilder ( ) ;
} else {
this . elements . tokenQuery . removeChild ( attr ) ;
}
}
addToken ( ) {
let c ;
2022-10-12 12:08:42 +00:00
let tokenQueryContent = '' ; //for ButtonFactory(prettyText)
let tokenQueryText = '' ; //for ButtonFactory(queryText)
2022-09-07 07:06:21 +00:00
this . elements . cancelBool = false ;
let emptyTokenCheck = false ;
2022-10-12 12:05:01 +00:00
if ( this . elements . ignoreCase . checked ) {
2022-09-07 07:06:21 +00:00
c = ' %c' ;
2022-10-12 12:05:01 +00:00
} else {
2022-09-07 07:06:21 +00:00
c = '' ;
}
2022-10-12 12:05:01 +00:00
for ( let element of this . elements . tokenQuery . childNodes ) {
2022-09-07 07:06:21 +00:00
tokenQueryContent += ' ' + element . firstChild . data + ' ' ;
tokenQueryText += decodeURI ( element . dataset . tokentext ) ;
2022-10-12 12:08:42 +00:00
if ( element . innerText . indexOf ( 'empty token' ) !== - 1 ) {
2022-09-07 07:06:21 +00:00
emptyTokenCheck = true ;
}
2022-08-03 14:21:11 +00:00
}
2022-10-12 12:05:01 +00:00
if ( this . elements . tokenQueryFilled === false ) {
2022-09-07 07:06:21 +00:00
switch ( this . elements . positionalAttr . value ) {
2022-10-12 12:08:42 +00:00
case 'word' :
if ( this . elements . wordInput . value === '' ) {
2022-09-07 07:06:21 +00:00
this . disableTokenSubmit ( ) ;
} else {
tokenQueryContent += ` word= ${ this . elements . wordInput . value } ${ c } ` ;
2022-10-20 13:52:25 +00:00
tokenQueryText += ` word=" ${ this . elements . wordInput . value } " ${ c } ` ;
2022-09-07 07:06:21 +00:00
this . elements . wordInput . value = '' ;
}
break ;
2022-10-12 12:08:42 +00:00
case 'lemma' :
if ( this . elements . lemmaInput . value === '' ) {
2022-09-07 07:06:21 +00:00
this . disableTokenSubmit ( ) ;
} else {
tokenQueryContent += ` lemma= ${ this . elements . lemmaInput . value } ${ c } ` ;
2022-10-20 13:52:25 +00:00
tokenQueryText += ` lemma=" ${ this . elements . lemmaInput . value } " ${ c } ` ;
2022-09-07 07:06:21 +00:00
this . elements . lemmaInput . value = '' ;
}
break ;
2022-10-12 12:08:42 +00:00
case 'english-pos' :
if ( this . elements . englishPos . value === 'default' ) {
2022-09-07 07:06:21 +00:00
this . disableTokenSubmit ( ) ;
} else {
tokenQueryContent += ` pos= ${ this . elements . englishPos . value } ` ;
2022-10-20 13:52:25 +00:00
tokenQueryText += ` pos=" ${ this . elements . englishPos . value } " ` ;
2022-09-07 07:06:21 +00:00
this . elements . englishPos . value = '' ;
}
break ;
2022-10-12 12:08:42 +00:00
case 'german-pos' :
if ( this . elements . germanPos . value === 'default' ) {
2022-09-07 07:06:21 +00:00
this . disableTokenSubmit ( ) ;
} else {
tokenQueryContent += ` pos= ${ this . elements . germanPos . value } ` ;
2022-10-20 13:52:25 +00:00
tokenQueryText += ` pos=" ${ this . elements . germanPos . value } " ` ;
2022-09-07 07:06:21 +00:00
this . elements . germanPos . value = '' ;
}
break ;
2022-10-12 12:08:42 +00:00
case 'simple-pos-button' :
if ( this . elements . simplePos . value === 'default' ) {
2022-09-07 07:06:21 +00:00
this . disableTokenSubmit ( ) ;
} else {
tokenQueryContent += ` simple_pos= ${ this . elements . simplePos . value } ` ;
2022-10-20 13:52:25 +00:00
tokenQueryText += ` simple_pos=" ${ this . elements . simplePos . value } " ` ;
2022-09-07 07:06:21 +00:00
this . elements . simplePos . value = '' ;
}
break ;
default :
this . wordBuilder ( ) ;
break ;
}
2022-07-13 12:06:22 +00:00
}
2022-09-07 07:06:21 +00:00
// cancelBool looks in disableTokenSubmit() whether a value is passed. If the input fields/dropdowns are empty (cancelBool === true), no token is added.
2022-10-12 12:05:01 +00:00
if ( this . elements . cancelBool === false ) {
2022-09-07 07:06:21 +00:00
// Square brackets are added only if it is not an empty token (where they are already present).
if ( emptyTokenCheck === false ) {
tokenQueryText = '[' + tokenQueryText + ']' ;
2022-10-20 13:52:25 +00:00
}
2022-09-07 07:06:21 +00:00
this . buttonfactory ( 'token' , tokenQueryContent , tokenQueryText ) ;
this . hideEverything ( ) ;
this . elements . positionalAttrArea . classList . add ( 'hide' ) ;
2022-10-12 12:08:42 +00:00
this . elements . tokenQuery . innerHTML = '' ;
2022-09-07 07:06:21 +00:00
}
}
disableTokenSubmit ( ) {
this . elements . cancelBool = true ;
2022-10-12 12:08:42 +00:00
this . elements . tokenSubmitButton . classList . add ( 'red' ) ;
2022-09-07 07:06:21 +00:00
this . elements . noValueMessage . classList . remove ( 'hide' ) ;
setTimeout ( ( ) => {
2022-10-12 12:08:42 +00:00
this . elements . tokenSubmitButton . classList . remove ( 'red' ) ;
2022-09-07 07:06:21 +00:00
} , 500 ) ;
setTimeout ( ( ) => {
this . elements . noValueMessage . classList . add ( 'hide' ) ;
} , 3000 ) ;
}
//#endregion General functions of the Token Builder
//#region Dropdown Select Handler
wordBuilder ( ) {
this . hideEverything ( ) ;
2022-10-12 12:08:42 +00:00
this . elements . wordInput . value = '' ;
this . elements . wordBuilder . classList . remove ( 'hide' ) ;
this . elements . inputOptions . classList . remove ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
this . elements . incidenceModifiersButton . classList . remove ( 'hide' ) ;
2022-10-12 12:08:42 +00:00
this . elements . conditionContainer . classList . remove ( 'hide' ) ;
this . elements . ignoreCaseCheckbox . classList . remove ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
// Resets materialize select field to default value
let SelectInstance = M . FormSelect . getInstance ( this . elements . positionalAttr ) ;
2022-10-12 12:08:42 +00:00
SelectInstance . input . value = 'word' ;
this . elements . positionalAttr . value = 'word' ;
2022-09-07 07:06:21 +00:00
}
lemmaBuilder ( ) {
this . hideEverything ( ) ;
2022-10-12 12:08:42 +00:00
this . elements . lemmaBuilder . classList . remove ( 'hide' ) ;
this . elements . inputOptions . classList . remove ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
this . elements . incidenceModifiersButton . classList . remove ( 'hide' ) ;
2022-10-12 12:08:42 +00:00
this . elements . conditionContainer . classList . remove ( 'hide' ) ;
this . elements . ignoreCaseCheckbox . classList . remove ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
}
englishPosHandler ( ) {
this . hideEverything ( ) ;
2022-10-12 12:08:42 +00:00
this . elements . englishPosBuilder . classList . remove ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
this . elements . incidenceModifiersButton . classList . remove ( 'hide' ) ;
2022-10-12 12:08:42 +00:00
this . elements . conditionContainer . classList . remove ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
// Resets materialize select dropdown
let selectInstance = M . FormSelect . getInstance ( this . elements . englishPos ) ;
2022-10-12 12:08:42 +00:00
selectInstance . input . value = 'English pos tagset' ;
this . elements . englishPos . value = 'default' ;
2022-09-07 07:06:21 +00:00
}
germanPosHandler ( ) {
this . hideEverything ( ) ;
2022-10-12 12:08:42 +00:00
this . elements . germanPosBuilder . classList . remove ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
this . elements . incidenceModifiersButton . classList . remove ( 'hide' ) ;
2022-10-12 12:08:42 +00:00
this . elements . conditionContainer . classList . remove ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
// Resets materialize select dropdown
let selectInstance = M . FormSelect . getInstance ( this . elements . germanPos ) ;
2022-10-12 12:08:42 +00:00
selectInstance . input . value = 'German pos tagset' ;
this . elements . germanPos . value = 'default' ;
2022-09-07 07:06:21 +00:00
}
simplePosBuilder ( ) {
this . hideEverything ( ) ;
2022-10-12 12:08:42 +00:00
this . elements . simplePosBuilder . classList . remove ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
this . elements . incidenceModifiersButton . classList . remove ( 'hide' ) ;
2022-10-12 12:08:42 +00:00
this . elements . conditionContainer . classList . remove ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
this . elements . simplePos . selectedIndex = 0 ;
// Resets materialize select dropdown
let selectInstance = M . FormSelect . getInstance ( this . elements . simplePos ) ;
2022-10-12 12:08:42 +00:00
selectInstance . input . value = 'simple_pos tagset' ;
this . elements . simplePos . value = 'default' ;
2022-09-07 07:06:21 +00:00
}
emptyTokenHandler ( ) {
2022-10-12 12:08:42 +00:00
this . tokenButtonfactory ( 'empty token' , '[]' ) ;
2022-09-07 07:06:21 +00:00
this . elements . tokenQueryFilled = true ;
this . hideEverything ( ) ;
this . elements . incidenceModifiersButton . classList . remove ( 'hide' ) ;
}
//#endregion Dropdown Select Handler
2022-10-12 12:08:42 +00:00
//#region Options to edit your token - Wildcard Charakter, Option Group, Incidence Modifiers, Ignore Case, 'and', 'or'
2022-09-07 07:06:21 +00:00
inputOptionHandler ( elem ) {
let input ;
if ( this . elements . wordBuilder . classList . contains ( 'hide' ) === false ) {
input = this . elements . wordInput ;
} else {
input = this . elements . lemmaInput ;
}
if ( elem === this . elements . optionGroup ) {
input . value += '( option1 | option2 )' ;
let firstIndex = input . value . indexOf ( 'option1' ) ;
let lastIndex = firstIndex + 'option1' . length ;
input . focus ( ) ;
input . setSelectionRange ( firstIndex , lastIndex ) ;
} else if ( elem === this . elements . wildcardChar ) {
input . value += '.' ;
}
}
nSubmitHandler ( ) {
let instance = M . Modal . getInstance ( this . elements . exactlyN ) ;
instance . close ( ) ;
switch ( this . elements . positionalAttr . value ) {
2022-10-12 12:08:42 +00:00
case 'word' :
this . elements . wordInput . value += ' {' + this . elements . nInput . value + '}' ;
2022-09-07 07:06:21 +00:00
break ;
2022-10-12 12:08:42 +00:00
case 'lemma' :
this . elements . lemmaInput . value += ' {' + this . elements . nInput . value + '}' ;
2022-09-07 07:06:21 +00:00
break ;
2022-10-12 12:08:42 +00:00
case 'english-pos' :
2022-09-07 07:06:21 +00:00
this . elements . tokenQueryFilled = true ;
2022-10-20 13:52:25 +00:00
this . tokenButtonfactory ( ` pos= ${ this . elements . englishPos . value } ` , ` pos=" ${ this . elements . englishPos . value } " ` ) ;
2022-10-12 12:08:42 +00:00
this . tokenButtonfactory ( '{' + this . elements . nInput . value + '}' , '{' + this . elements . nInput . value + '}' ) ;
this . elements . englishPosBuilder . classList . add ( 'hide' ) ;
this . elements . incidenceModifiersButton . classList . add ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
break ;
2022-10-12 12:08:42 +00:00
case 'german-pos' :
2022-09-07 07:06:21 +00:00
this . elements . tokenQueryFilled = true ;
2022-10-20 13:52:25 +00:00
this . tokenButtonfactory ( ` pos= ${ this . elements . germanPos . value } ` , ` pos=" ${ this . elements . germanPos . value } " ` ) ;
2022-10-12 12:08:42 +00:00
this . tokenButtonfactory ( '{' + this . elements . nInput . value + '}' , '{' + this . elements . nInput . value + '}' ) ;
this . elements . germanPosBuilder . classList . add ( 'hide' ) ;
this . elements . incidenceModifiersButton . classList . add ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
break ;
2022-10-12 12:08:42 +00:00
case 'simple-pos-button' :
2022-09-07 07:06:21 +00:00
this . elements . tokenQueryFilled = true ;
2022-10-20 13:52:25 +00:00
this . tokenButtonfactory ( ` simple_pos= ${ this . elements . simplePos . value } ` , ` simple_pos=" ${ this . elements . simplePos . value } " ` ) ;
2022-10-12 12:08:42 +00:00
this . tokenButtonfactory ( '{' + this . elements . nInput . value + '}' , '{' + this . elements . nInput . value + '}' ) ;
this . elements . simplePosBuilder . classList . add ( 'hide' ) ;
this . elements . incidenceModifiersButton . classList . add ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
break ;
2022-10-12 12:08:42 +00:00
case 'empty-token' :
this . tokenButtonfactory ( '{' + this . elements . nInput . value + '}' , '{' + this . elements . nInput . value + '}' ) ;
2022-09-07 07:06:21 +00:00
break ;
default :
break ;
}
}
nmSubmitHandler ( ) {
let instance = M . Modal . getInstance ( this . elements . betweenNM ) ;
instance . close ( ) ;
2022-09-07 12:22:59 +00:00
switch ( this . elements . positionalAttr . value ) {
2022-10-12 12:08:42 +00:00
case 'word' :
2022-09-07 12:22:59 +00:00
this . elements . wordInput . value += ` { ${ this . elements . nmInput . value } , ${ this . elements . mInput . value } } ` ;
break ;
2022-10-12 12:08:42 +00:00
case 'lemma' :
2022-09-07 12:22:59 +00:00
this . elements . lemmaInput . value += ` { ${ this . elements . nmInput . value } , ${ this . elements . mInput . value } } ` ;
break ;
2022-10-12 12:08:42 +00:00
case 'english-pos' :
2022-09-07 12:22:59 +00:00
this . elements . tokenQueryFilled = true ;
2022-10-20 13:52:25 +00:00
this . tokenButtonfactory ( ` pos= ${ this . elements . englishPos . value } ` , ` pos=" ${ this . elements . englishPos . value } " ` ) ;
2022-09-07 12:22:59 +00:00
this . tokenButtonfactory ( ` { ${ this . elements . nmInput . value } , ${ this . elements . mInput . value } } ` , ` { ${ this . elements . nmInput . value } , ${ this . elements . mInput . value } } ` ) ;
2022-10-12 12:08:42 +00:00
this . elements . englishPosBuilder . classList . add ( 'hide' ) ;
this . elements . incidenceModifiersButton . classList . add ( 'hide' ) ;
2022-09-07 12:22:59 +00:00
break ;
2022-10-12 12:08:42 +00:00
case 'german-pos' :
2022-09-07 12:22:59 +00:00
this . elements . tokenQueryFilled = true ;
2022-10-20 13:52:25 +00:00
this . tokenButtonfactory ( ` pos= ${ this . elements . germanPos . value } ` , ` pos=" ${ this . elements . germanPos . value } " ` ) ;
2022-09-07 12:22:59 +00:00
this . tokenButtonfactory ( ` { ${ this . elements . nmInput . value } , ${ this . elements . mInput . value } } ` , ` { ${ this . elements . nmInput . value } , ${ this . elements . mInput . value } } ` ) ;
2022-10-12 12:08:42 +00:00
this . elements . germanPosBuilder . classList . add ( 'hide' ) ;
this . elements . incidenceModifiersButton . classList . add ( 'hide' ) ;
2022-09-07 12:22:59 +00:00
break ;
2022-10-12 12:08:42 +00:00
case 'simple-pos-button' :
2022-09-07 12:22:59 +00:00
this . elements . tokenQueryFilled = true ;
2022-10-20 13:52:25 +00:00
this . tokenButtonfactory ( ` simple_pos= ${ this . elements . simplePos . value } ` , ` simple_pos=" ${ this . elements . simplePos . value } " ` ) ;
2022-09-07 12:22:59 +00:00
this . tokenButtonfactory ( ` { ${ this . elements . nmInput . value } , ${ this . elements . mInput . value } } ` , ` { ${ this . elements . nmInput . value } , ${ this . elements . mInput . value } } ` ) ;
2022-10-12 12:08:42 +00:00
this . elements . simplePosBuilder . classList . add ( 'hide' ) ;
this . elements . incidenceModifiersButton . classList . add ( 'hide' ) ;
2022-09-07 12:22:59 +00:00
break ;
2022-10-12 12:08:42 +00:00
case 'empty-token' :
2022-09-07 12:22:59 +00:00
this . tokenButtonfactory ( ` { ${ this . elements . nmInput . value } , ${ this . elements . mInput . value } } ` , ` { ${ this . elements . nmInput . value } , ${ this . elements . mInput . value } } ` ) ;
break ;
default :
break ;
}
2022-09-07 07:06:21 +00:00
}
incidenceModifiersHandler ( elem ) {
// For word and lemma, the incidence modifiers are inserted in the input field. For the others, one or two chips are created which contain the respective value of the token and the incidence modifier.
2022-10-12 12:08:42 +00:00
if ( this . elements . positionalAttr . value === 'empty-token' ) {
2022-09-07 07:06:21 +00:00
this . tokenButtonfactory ( elem . innerText , elem . dataset . token ) ;
2022-10-12 12:08:42 +00:00
} else if ( this . elements . positionalAttr . value === 'english-pos' ) {
2022-10-20 13:52:25 +00:00
this . tokenButtonfactory ( ` pos= ${ this . elements . englishPos . value } ` , ` pos=" ${ this . elements . englishPos . value } " ` ) ;
2022-09-07 07:06:21 +00:00
this . tokenButtonfactory ( elem . innerText , elem . dataset . token ) ;
2022-10-12 12:08:42 +00:00
this . elements . englishPosBuilder . classList . add ( 'hide' ) ;
this . elements . incidenceModifiersButton . classList . add ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
this . elements . tokenQueryFilled = true ;
2022-10-12 12:08:42 +00:00
} else if ( this . elements . positionalAttr . value === 'german-pos' ) {
2022-10-20 13:52:25 +00:00
this . tokenButtonfactory ( ` pos= ${ this . elements . germanPos . value } ` , ` pos=" ${ this . elements . germanPos . value } " ` ) ;
2022-09-07 07:06:21 +00:00
this . tokenButtonfactory ( elem . innerText , elem . dataset . token ) ;
2022-10-12 12:08:42 +00:00
this . elements . germanPosBuilder . classList . add ( 'hide' ) ;
this . elements . incidenceModifiersButton . classList . add ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
this . elements . tokenQueryFilled = true ;
2022-10-12 12:08:42 +00:00
} else if ( this . elements . positionalAttr . value === 'simple-pos-button' ) {
2022-10-20 13:52:25 +00:00
this . tokenButtonfactory ( ` simple_pos= ${ this . elements . simplePos . value } ` , ` simple_pos=" ${ this . elements . simplePos . value } " ` ) ;
2022-09-07 07:06:21 +00:00
this . tokenButtonfactory ( elem . innerText , elem . dataset . token ) ;
2022-10-12 12:08:42 +00:00
this . elements . simplePosBuilder . classList . add ( 'hide' ) ;
this . elements . incidenceModifiersButton . classList . add ( 'hide' ) ;
2022-09-07 07:06:21 +00:00
this . elements . tokenQueryFilled = true ;
} else {
let input ;
if ( this . elements . wordBuilder . classList . contains ( 'hide' ) === false ) {
input = this . elements . wordInput ;
} else {
input = this . elements . lemmaInput ;
}
2022-07-13 12:06:22 +00:00
2022-09-07 07:06:21 +00:00
input . value += ' ' + elem . dataset . token ;
}
}
orHandler ( ) {
2022-10-12 12:08:42 +00:00
this . conditionHandler ( 'or' , ' | ' ) ;
2022-09-07 07:06:21 +00:00
}
andHandler ( ) {
2022-10-12 12:08:42 +00:00
this . conditionHandler ( 'and' , ' & ' ) ;
2022-09-07 07:06:21 +00:00
}
conditionHandler ( conditionText , conditionQueryContent ) {
this . hideEverything ( ) ;
let tokenQueryContent ;
let tokenQueryText ;
let c ;
2022-10-12 12:05:01 +00:00
if ( this . elements . ignoreCase . checked ) {
2022-09-07 07:06:21 +00:00
c = ' %c' ;
2022-10-12 12:05:01 +00:00
} else {
2022-09-07 07:06:21 +00:00
c = '' ;
}
switch ( this . elements . positionalAttr . value ) {
2022-10-12 12:08:42 +00:00
case 'word' :
2022-09-07 07:06:21 +00:00
tokenQueryContent = ` word= ${ this . elements . wordInput . value } ${ c } ` ;
2022-10-20 13:52:25 +00:00
tokenQueryText = ` word=" ${ this . elements . wordInput . value } " ${ c } ` ;
2022-09-07 07:06:21 +00:00
this . elements . wordInput . value = '' ;
break ;
2022-10-12 12:08:42 +00:00
case 'lemma' :
2022-09-07 07:06:21 +00:00
tokenQueryContent = ` lemma= ${ this . elements . lemmaInput . value } ${ c } ` ;
2022-10-20 13:52:25 +00:00
tokenQueryText = ` lemma=" ${ this . elements . lemmaInput . value } " ${ c } ` ;
2022-09-07 07:06:21 +00:00
this . elements . lemmaInput . value = '' ;
break ;
2022-10-12 12:08:42 +00:00
case 'english-pos' :
2022-09-07 07:06:21 +00:00
tokenQueryContent = ` pos= ${ this . elements . englishPos . value } ` ;
2022-10-20 13:52:25 +00:00
tokenQueryText = ` pos=" ${ this . elements . englishPos . value } " ` ;
2022-09-07 07:06:21 +00:00
this . elements . englishPos . value = '' ;
break ;
2022-10-12 12:08:42 +00:00
case 'german-pos' :
2022-09-07 07:06:21 +00:00
tokenQueryContent = ` pos= ${ this . elements . germanPos . value } ` ;
2022-10-20 13:52:25 +00:00
tokenQueryText = ` pos=" ${ this . elements . germanPos . value } " ` ;
2022-09-07 07:06:21 +00:00
this . elements . germanPos . value = '' ;
break ;
2022-10-12 12:08:42 +00:00
case 'simple-pos-button' :
2022-09-07 07:06:21 +00:00
tokenQueryContent = ` simple_pos= ${ this . elements . simplePos . value } ` ;
2022-10-20 13:52:25 +00:00
tokenQueryText = ` simple_pos=" ${ this . elements . simplePos . value } " ` ;
2022-09-07 07:06:21 +00:00
this . elements . simplePos . value = '' ;
break ;
default :
this . wordBuilder ( ) ;
break ;
}
this . tokenButtonfactory ( tokenQueryContent , tokenQueryText ) ;
this . tokenButtonfactory ( conditionText , conditionQueryContent ) ;
this . wordBuilder ( ) ;
}
2022-10-12 12:08:42 +00:00
//#endregion Options to edit your token - Wildcard Charakter, Option Group, Incidence Modifiers, Ignore Case, 'and', 'or'
2022-09-07 07:06:21 +00:00
//#endregion Token Attribute Builder Functions
2022-10-12 12:05:01 +00:00
// ##########################################################################
// ############ Structural Attribute Builder Functions ######################
// ##########################################################################
2022-09-07 07:06:21 +00:00
//#region Structural Attribute Builder Functions
addSentence ( ) {
this . hideEverything ( ) ;
2022-10-12 12:05:01 +00:00
if ( this . elements . sentence . text === 'End Sentence' ) {
2022-09-07 07:06:21 +00:00
this . buttonfactory ( 'end-sentence' , 'Sentence End' , '</s>' ) ;
this . elements . sentence . innerHTML = 'Sentence' ;
} else {
this . buttonfactory ( 'start-sentence' , 'Sentence Start' , '<s>' ) ;
this . elements . queryContent . push ( 'sentence' ) ;
this . elements . sentence . innerHTML = 'End Sentence' ;
}
}
addEntity ( ) {
if ( this . elements . entity . text === 'End Entity' ) {
let queryText ;
if ( this . elements . entityAnyType === false ) {
queryText = '</ent_type>' ;
} else {
queryText = '</ent>' ;
}
this . buttonfactory ( 'end-entity' , 'Entity End' , queryText ) ;
this . elements . entity . innerHTML = 'Entity' ;
} else {
this . hideEverything ( ) ;
2022-10-12 12:08:42 +00:00
this . elements . entityBuilder . classList . remove ( 'hide' ) ;
window . location . href = '#entity-builder' ;
2022-09-07 07:06:21 +00:00
}
}
englishEntTypeHandler ( ) {
2022-10-20 13:52:25 +00:00
this . buttonfactory ( 'start-entity' , 'Entity Type=' + this . elements . englishEntType . value , '<ent_type="' + this . elements . englishEntType . value + '">' ) ;
2022-09-07 07:06:21 +00:00
this . elements . entity . innerHTML = 'End Entity' ;
this . hideEverything ( ) ;
this . elements . entityAnyType = false ;
// Resets materialize select dropdown
let SelectInstance = M . FormSelect . getInstance ( this . elements . englishEntType ) ;
2022-10-12 12:08:42 +00:00
SelectInstance . input . value = 'English ent_type' ;
this . elements . englishEntType . value = 'default' ;
2022-09-07 07:06:21 +00:00
}
germanEntTypeHandler ( ) {
2022-10-20 13:52:25 +00:00
this . buttonfactory ( 'start-entity' , 'Entity Type=' + this . elements . germanEntType . value , '<ent_type="' + this . elements . germanEntType . value + '">' ) ;
2022-09-07 07:06:21 +00:00
this . elements . entity . innerHTML = 'End Entity' ;
this . hideEverything ( ) ;
this . elements . entityAnyType = false ;
// Resets materialize select dropdown
let SelectInstance = M . FormSelect . getInstance ( this . elements . germanEntType ) ;
2022-10-12 12:08:42 +00:00
SelectInstance . input . value = 'German ent_type' ;
this . elements . germanEntType . value = 'default' ;
2022-09-07 07:06:21 +00:00
}
emptyEntityButton ( ) {
this . buttonfactory ( 'start-empty-entity' , 'Entity Start' , '<ent>' ) ;
this . elements . entity . innerHTML = 'End Entity' ;
this . hideEverything ( ) ;
this . elements . entityAnyType = true ;
}
addTextAnnotation ( ) {
this . hideEverything ( ) ;
2022-10-12 12:08:42 +00:00
this . elements . textAnnotationBuilder . classList . remove ( 'hide' ) ;
window . location . href = '#text-annotation-builder' ;
2022-09-07 07:06:21 +00:00
// Resets materialize select dropdown
let SelectInstance = M . FormSelect . getInstance ( this . elements . textAnnotationOptions ) ;
2022-10-12 12:08:42 +00:00
SelectInstance . input . value = 'address' ;
this . elements . textAnnotationOptions . value = 'address' ;
this . elements . textAnnotationInput . value = '' ;
2022-09-07 07:06:21 +00:00
}
textAnnotationSubmitHandler ( ) {
if ( this . elements . textAnnotationInput . value === '' ) {
this . elements . textAnnotationSubmit . classList . add ( 'red' ) ;
this . elements . noValueMetadataMessage . classList . remove ( 'hide' ) ;
setTimeout ( ( ) => {
this . elements . textAnnotationSubmit . classList . remove ( 'red' ) ;
} , 500 ) ;
setTimeout ( ( ) => {
this . elements . noValueMetadataMessage . classList . add ( 'hide' ) ;
} , 3000 ) ;
} else {
2022-10-12 12:08:42 +00:00
let queryText = ` :: match.text_ ${ this . elements . textAnnotationOptions . value } =' ${ this . elements . textAnnotationInput . value } ' ` ;
2022-09-07 07:06:21 +00:00
this . buttonfactory ( 'text-annotation' , ` ${ this . elements . textAnnotationOptions . value } = ${ this . elements . textAnnotationInput . value } ` , queryText ) ;
this . hideEverything ( ) ;
}
}
2022-10-13 13:15:53 +00:00
//#endregion Structural Attribute Builder Functions
2022-07-13 12:06:22 +00:00
}