MediaWiki

Difference between revisions of "LexemeQueriesGenerator.js"

Line 1: Line 1:
console.log("User:Yug/MediaWiki:OOUI.js script loaded/ran");
+
/* TODO
 +
1) List of languages with recordings AND number of speakers
 +
See base : https://lingualibre.org/wiki/LinguaLibre:List_of_languages
 +
See nbSp : https://w.wiki/4ZB3
 +
 
 +
Finish hacking based on https://jsfiddle.net/hugolpz/rygo9s5b/
 +
1) getData from elements
 +
2) Identify suitable query
 +
3) Edit suitable query
 +
4) Run/Open Query
 +
 
 +
Improve Query with federate SPARQL including LinguaLibre
 +
1) Explore
 +
 
 +
Add to LinguaLibre
 +
1) Add to [[User:Yug/OOUI]]
 +
2) Migrate to general space.
 +
 
 +
Translate
 +
1) Find a what to translate ?
 +
 
 +
Extension ?
 +
1) Explore
 +
*/
 +
 
 +
 
 
// Toolbox
 
// Toolbox
 
var runQuery = function(){
 
var runQuery = function(){
Line 5: Line 30:
 
}
 
}
  
// Data
+
// Data & options
var languagesArray1 = [
+
var baseLanguages = [ //Major languages: cmn, spa, eng, fra, ara, rus, hin, swa
       new OO.ui.MenuOptionWidget({ data: 'Q113', label: 'cmn - Mandarin Chinese' }),
+
       // data https://w.wiki/4ZB3
       new OO.ui.MenuOptionWidget({ data: 'Q34', label: 'mar - Marathi' }),
+
      { data:'Q13955', ll:'', label:'ara — Arabic' },
       new OO.ui.MenuOptionWidget({ data: 'Q209', label: 'bre - Breton' })
+
      { data:'Q9610', ll:'', label:'ben — Bengali' },
 +
      { data:'Q9192', ll:'Q113', label:'cmn — MandarinChinese' } ,
 +
      { data:'Q188', ll:'', label:'deu — German' },
 +
      { data:'Q1860', ll:'', label:'eng — English' },
 +
      { data:'Q150', ll:'', label:'fra — French' },
 +
      { data:'Q1568', ll:'', label:'hin — Hindi' },
 +
      { data:'Q5287', ll:'', label:'jpn — Japanese' },
 +
       { data:'Q1571', ll:'Q34', label:'mar Marathi' },
 +
       { data:'Q58635', ll:'', label:'pan — Punjabi' },
 +
      { data:'Q5146', ll:'', label:'por — Portuguese' },
 +
      { data:'Q7737', ll:'', label:'rus — Russian' },
 +
      { data:'Q1321', ll:'', label:'spa — Spanish' },
 
     ],
 
     ],
     languagesArrayB = [
+
     availableLanguages = [
       { data: 'Q113', label: 'cmn - Mandarin Chinese' },
+
       { data:'Q13955', ll:'', label:'ara — Arabic' },
       { data: 'Q34', label: 'mar - Marathi' },
+
      { data:'Q9610', ll:'', label:'ben — Bengali' },
       { data: 'Q209', label: 'bre - Breton' }
+
      { data: 'Q12107', ll:'Q209', label: 'bre: Breton' }, // lili
 +
      { data:'Q9192', ll:'Q113', label:'cmn — MandarinChinese' } ,
 +
      { data:'Q188', ll:'', label:'deu — German' },
 +
      { data:'Q1860', ll:'', label:'eng — English' },
 +
      { data:'Q33298', ll:'', label:'fil — Filipino' },
 +
      { data:'Q150', ll:'', label:'fra — French' },
 +
      { data:'Q33454', ll:'', label:'ful — Fula' },
 +
      { data:'Q56475', ll:'', label:'hau — Hausa' },
 +
      { data:'Q1568', ll:'', label:'hin — Hindi' },
 +
      { data:'Q9240', ll:'', label:'ind — Indonesian' },
 +
      { data:'Q652', ll:'', label:'ita — Italian' },
 +
      { data:'Q33549', ll:'', label:'jav — Javanese' },
 +
       { data:'Q5287', ll:'', label:'jpn — Japanese' },
 +
      { data:'Q9176', ll:'', label:'kor — Korean' },
 +
      { data:'Q1571', ll:'Q34', label:'mar Marathi' },
 +
       { data:'Q9237', ll:'', label:'msa — Malay' },
 +
      { data:'Q58635', ll:'', label:'pan — Punjabi' },
 +
      { data:'Q5146', ll:'', label:'por — Portuguese' },
 +
      { data:'Q7737', ll:'', label:'rus — Russian' },
 +
      { data:'Q1321', ll:'', label:'spa — Spanish' },
 +
      { data:'Q5885', ll:'', label:'tam — Tamil' },
 +
      { data:'Q8097', ll:'', label:'tel — Telugu' },
 +
      { data:'Q256', ll:'', label:'tur — Turkish' },
 +
      { data:'Q1617', ll:'', label:'urd — Urdu' },
 +
      { data:'Q9199', ll:'', label:'vie — Vietnamese' },
 
     ],
 
     ],
 +
    languagesArray = [ ...availableLanguages ],
 
     posArray = [
 
     posArray = [
       new OO.ui.MenuOptionWidget({ data: 'Q24905', label: 'verb' }),
+
       { data: 'Q1084', label: 'noun' },
       new OO.ui.MenuOptionWidget({ data: 'Q34698', label: 'adjective' }),
+
      { data: 'Q36224', label: 'pronoun' },
       new OO.ui.MenuOptionWidget({ data: 'Q380057', label: 'adverb' }),
+
      { data: 'Q24905', label: 'verb' },
       new OO.ui.MenuOptionWidget({ data: 'Q1084', label: 'noun' })
+
       { data: 'Q380057', label: 'adverb' },
    ],
+
      { data: 'Q34698', label: 'adjective' },
 +
       { data: 'Q21087400', label: 'quantitative'},
 +
      { data: 'Q83034', label: 'interjection' },
 +
      { data: 'Q4833830', label: 'preposition' },
 +
      { data: 'Q103184', label: 'article' },
 +
       { data: 'Q36484', label: 'conjunction' },
 +
    ].map(o => new OO.ui.MenuOptionWidget({ data: o.data, label: o.label })),
 
     infoTypesArray = [
 
     infoTypesArray = [
       new OO.ui.MenuOptionWidget({ data: '1', label: 'Just look !' }),
+
       { data: '1', label: 'Just look !' },
       new OO.ui.MenuOptionWidget({ data: '2', label: 'Sense' }),
+
       { data: '2', label: 'Sense' },
       new OO.ui.MenuOptionWidget({ data: '3', label: 'Sense, definition' }),
+
       { data: '3', label: 'Sense, definition' },
       new OO.ui.MenuOptionWidget({ data: '4', label: 'Sense, definition and examples'}),
+
       { data: '4', label: 'Sense, definition and examples'},
     ],
+
     ].map(o => new OO.ui.MenuOptionWidget({ data: o.data, label: o.label })),
    languagesArray2 = [
+
    languagesArrayT = [ ...baseLanguages, ]
      new OO.ui.MenuOptionWidget({ data: 'Q113', label: 'cmn - Mandarin Chinese' }),
+
.map(o => new OO.ui.MenuOptionWidget({ data: o.data, label: o.label })),
      new OO.ui.MenuOptionWidget({ data: 'Q34',  label: 'mar - Marathi' }),
 
      new OO.ui.MenuOptionWidget({ data: 'Q209', label: 'bre - Breton' })
 
    ],
 
 
     endpointsArray = [
 
     endpointsArray = [
       new OO.ui.RadioOptionWidget({ data: 'wikidata', label: 'Wikidata', selected: true }),
+
       { data: 'wikidata', label: 'Wikidata', selected: true },
       new OO.ui.RadioOptionWidget({ data: 'Dbnary', label: 'Dbnary' }),
+
       { data: 'Dbnary', label: 'Dbnary' },
       //new OO.ui.RadioOptionWidget({ data: 'LinguaLibre', label: 'LinguaLibre' }),
+
       //{ data: 'LinguaLibre', label: 'LinguaLibre' },
     ];
+
     ].map(o => new OO.ui.RadioOptionWidget({ data: o.data, label: o.label }));
  
 
// Elements
 
// Elements
 
var lemma = new OO.ui.TextInputWidget({
 
var lemma = new OO.ui.TextInputWidget({
 
     id: 'lqg-lemma',
 
     id: 'lqg-lemma',
 +
    icon: 'search',
 
     placeholder: 'book',
 
     placeholder: 'book',
 
     value: 'book',
 
     value: 'book',
label: 'Word',
+
label: 'Word to search',
    icon: 'search'
+
  }),
    }),
+
   languagesC = new OO.ui.ComboBoxInputWidget({ // ComboBox
   languages = new OO.ui.DropdownWidget({
+
     id: 'lqg-languagesC',
     id: 'lqg-languages',
+
placeholder : 'Target language',
label: 'Source languages',
+
    options: languagesArray,
menu: { items: languagesArray1 }
+
    menu: { filterFromInput: true, filterMode : 'substring' }
}),
 
  languagesB = new OO.ui.ComboBoxInputWidget({
 
 
   // value: 'Q34',
 
   // value: 'Q34',
    options: languagesArrayB,
 
    id: 'lqg-languages',
 
placeholder : 'Source languages',
 
 
}),
 
}),
 
   pos = new OO.ui.DropdownWidget( {
 
   pos = new OO.ui.DropdownWidget( {
Line 65: Line 125:
 
   infoTypes = new OO.ui.DropdownWidget({
 
   infoTypes = new OO.ui.DropdownWidget({
 
     id: 'lqg-infoTypes',
 
     id: 'lqg-infoTypes',
label: 'Information to fetch if any',
+
label: 'Information to fetch ... (if any)',
 
menu: { items: infoTypesArray }
 
menu: { items: infoTypesArray }
 
}),
 
}),
 
   translations = new OO.ui.DropdownWidget({
 
   translations = new OO.ui.DropdownWidget({
 
     id: 'lqg-translations',
 
     id: 'lqg-translations',
label: 'Translations',
+
label: 'Translations to fetch ... (if any)',
menu: { items: languagesArray2 }
+
menu: { items: languagesArrayT }
 
}),
 
}),
 
   enpoints =  new OO.ui.RadioSelectWidget({  
 
   enpoints =  new OO.ui.RadioSelectWidget({  
 
     id: 'lqg-endpoints',
 
     id: 'lqg-endpoints',
 
   label: 'Radios buttons',
 
   label: 'Radios buttons',
   
 
 
items: endpointsArray  
 
items: endpointsArray  
 
} ),
 
} ),
Line 97: Line 156:
 
} );
 
} );
 
    
 
    
 
+
// An example of a fieldset with horizontal layout.
  // An example of a fieldset with horizontal layout.
 
 
 
 
var fieldset = new OO.ui.FieldsetLayout( {
 
var fieldset = new OO.ui.FieldsetLayout( {
 
label: 'Queries Generator for Wikidata Lexemes'
 
label: 'Queries Generator for Wikidata Lexemes'
 
} );
 
} );
 
 
 
fieldset.addItems( [  
 
fieldset.addItems( [  
 
   new OO.ui.FieldLayout(
 
   new OO.ui.FieldLayout(
Line 112: Line 167:
 
           lemma,
 
           lemma,
 
           pos,
 
           pos,
           languages,
+
           languagesC,
        ]}),
 
        new OO.ui.HorizontalLayout( { items: [
 
          languagesB,
 
 
           infoTypes,
 
           infoTypes,
           translations
+
           translations,
 
         ]}),
 
         ]}),
 
         new OO.ui.HorizontalLayout( { items: [
 
         new OO.ui.HorizontalLayout( { items: [
Line 128: Line 180:
 
         queryDisplay
 
         queryDisplay
 
       ]
 
       ]
     }))
+
     }),{
 +
label: 'Select the suitable values to build your Wikidata Lexemes Query.',
 +
align: 'top'
 +
})
 
]
 
]
 
);
 
);
 +
$( "#lqg" ).append( fieldset.$element );
  
// Add an horizontal field layout
+
// Check data
 +
var checkAvailableData = function(identity,element){
 +
// console.log('2',languages)
 +
console.log(identity+'a getElementId(): ',element.getElementId())
 +
console.log(identity+'b getData(): ',element.getData())
 +
  console.log(identity+'c getValue(): ',element.getValue())
 +
}
  
$( "#lqg" ).append( fieldset.$element );
+
$('#lqg-lemma').on('focusout',function() {checkAvailableData(1,lemma);})
 +
$('#lqg-languages').on('focusout',function() { checkAvailableData(2,languagesA);});

Revision as of 22:42, 15 December 2021

/* TODO
1) List of languages with recordings AND number of speakers
See base : https://lingualibre.org/wiki/LinguaLibre:List_of_languages
See nbSp : https://w.wiki/4ZB3

Finish hacking based on https://jsfiddle.net/hugolpz/rygo9s5b/
1) getData from elements
2) Identify suitable query
3) Edit suitable query
4) Run/Open Query

Improve Query with federate SPARQL including LinguaLibre
1) Explore

Add to LinguaLibre
1) Add to [[User:Yug/OOUI]]
2) Migrate to general space.

Translate
1) Find a what to translate ?

Extension ?
1) Explore
*/


// Toolbox
var runQuery = function(){
 return 'https://query.wikidata.org/#';
}

// Data & options
var baseLanguages = [ //Major languages: cmn, spa, eng, fra, ara, rus, hin, swa
      // data https://w.wiki/4ZB3
      { data:'Q13955', ll:'', label:'ara — Arabic' },
      { data:'Q9610', ll:'', label:'ben — Bengali' },
      { data:'Q9192', ll:'Q113', label:'cmn — MandarinChinese' } ,
      { data:'Q188', ll:'', label:'deu — German' },
      { data:'Q1860', ll:'', label:'eng — English' },
      { data:'Q150', ll:'', label:'fra — French' },
      { data:'Q1568', ll:'', label:'hin — Hindi' },
      { data:'Q5287', ll:'', label:'jpn — Japanese' },
      { data:'Q1571', ll:'Q34', label:'mar — Marathi' },
      { data:'Q58635', ll:'', label:'pan — Punjabi' },
      { data:'Q5146', ll:'', label:'por — Portuguese' },
      { data:'Q7737', ll:'', label:'rus — Russian' },
      { data:'Q1321', ll:'', label:'spa — Spanish' },
    ],
    availableLanguages = [
      { data:'Q13955', ll:'', label:'ara — Arabic' },
      { data:'Q9610', ll:'', label:'ben — Bengali' },
      { data: 'Q12107', ll:'Q209', label: 'bre: Breton' }, // lili 
      { data:'Q9192', ll:'Q113', label:'cmn — MandarinChinese' } ,
      { data:'Q188', ll:'', label:'deu — German' },
      { data:'Q1860', ll:'', label:'eng — English' },
      { data:'Q33298', ll:'', label:'fil — Filipino' },
      { data:'Q150', ll:'', label:'fra — French' },
      { data:'Q33454', ll:'', label:'ful — Fula' },
      { data:'Q56475', ll:'', label:'hau — Hausa' },
      { data:'Q1568', ll:'', label:'hin — Hindi' },
      { data:'Q9240', ll:'', label:'ind — Indonesian' },
      { data:'Q652', ll:'', label:'ita — Italian' },
      { data:'Q33549', ll:'', label:'jav — Javanese' },
      { data:'Q5287', ll:'', label:'jpn — Japanese' },
      { data:'Q9176', ll:'', label:'kor — Korean' },
      { data:'Q1571', ll:'Q34', label:'mar — Marathi' },
      { data:'Q9237', ll:'', label:'msa — Malay' },
      { data:'Q58635', ll:'', label:'pan — Punjabi' },
      { data:'Q5146', ll:'', label:'por — Portuguese' },
      { data:'Q7737', ll:'', label:'rus — Russian' },
      { data:'Q1321', ll:'', label:'spa — Spanish' },
      { data:'Q5885', ll:'', label:'tam — Tamil' },
      { data:'Q8097', ll:'', label:'tel — Telugu' },
      { data:'Q256', ll:'', label:'tur — Turkish' },
      { data:'Q1617', ll:'', label:'urd — Urdu' },
      { data:'Q9199', ll:'', label:'vie — Vietnamese' },
    ],
    languagesArray = [ ...availableLanguages ],
    posArray = [
      { data: 'Q1084', label: 'noun' },
      { data: 'Q36224', label: 'pronoun' },
      { data: 'Q24905', label: 'verb' },
      { data: 'Q380057', label: 'adverb' },
      { data: 'Q34698', label: 'adjective' },
      { data: 'Q21087400', label: 'quantitative'},
      { data: 'Q83034', label: 'interjection' },
      { data: 'Q4833830', label: 'preposition' },
      { data: 'Q103184', label: 'article' },
      { data: 'Q36484', label: 'conjunction' },
    ].map(o => new OO.ui.MenuOptionWidget({ data: o.data, label: o.label })),
    infoTypesArray = [
      { data: '1', label: 'Just look !' },
      { data: '2', label: 'Sense' },
      { data: '3', label: 'Sense, definition' },
      { data: '4', label: 'Sense, definition and examples'},
    ].map(o => new OO.ui.MenuOptionWidget({ data: o.data, label: o.label })),
    languagesArrayT = [ ...baseLanguages, ]
.map(o => new OO.ui.MenuOptionWidget({ data: o.data, label: o.label })),
    endpointsArray = [
      { data: 'wikidata', label: 'Wikidata', selected: true },
      { data: 'Dbnary', label: 'Dbnary' },
      //{ data: 'LinguaLibre', label: 'LinguaLibre' },
    ].map(o => new OO.ui.RadioOptionWidget({ data: o.data, label: o.label }));

// Elements
var lemma = new OO.ui.TextInputWidget({
    id: 'lqg-lemma',
    icon: 'search',
    placeholder: 'book',
    value: 'book',
		label: 'Word to search',
  }),
  languagesC = new OO.ui.ComboBoxInputWidget({ // ComboBox
    id: 'lqg-languagesC',
		placeholder : 'Target language',
    options: languagesArray,
    menu: {	filterFromInput: true, filterMode : 'substring'	}
  	// value: 'Q34',
	}),
  pos = new OO.ui.DropdownWidget( {
    id: 'lqg-pos',
		label: 'Part-of-speech',
		menu: { items: posArray }
	}),
  infoTypes = new OO.ui.DropdownWidget({
    id: 'lqg-infoTypes',
		label: 'Information to fetch ... (if any)',
		menu: { items: infoTypesArray }
	}),
  translations = new OO.ui.DropdownWidget({
    id: 'lqg-translations',
		label: 'Translations to fetch ... (if any)',
		menu: { items: languagesArrayT }
	}),
  enpoints =  new OO.ui.RadioSelectWidget({ 
    id: 'lqg-endpoints',
  	label: 'Radios buttons',
		items: endpointsArray 
	} ),
  generate = new OO.ui.ButtonWidget({ id: 'lqg-generate', label: 'Generate' } ),
  run = new OO.ui.ButtonWidget({ 
    id: 'lqg-pos',
    label:'Run !', 
    href:runQuery(), 
    target:'new' 
  }),
  limit = new OO.ui.CheckboxInputWidget({ id: 'lqg-limit', selected: true, }),
  limitLabel = new OO.ui.LabelWidget( { label: 'Limit to 100 (faster)' }),
  queryDisplay = new OO.ui.MultilineTextInputWidget( { 
    id: 'lqg-pos',
		value: `Query will appear here.\n\n\n\n\n\n`,
		multiline: true,
		autosize: true,
    minRows: 10,
		maxRows: 20
	} );
  
// An example of a fieldset with horizontal layout.
var fieldset = new OO.ui.FieldsetLayout( {
		label: 'Queries Generator for Wikidata Lexemes'
	} );
fieldset.addItems( [ 
  new OO.ui.FieldLayout(
    new OO.ui.Widget( {
      content: [ 
        new OO.ui.HorizontalLayout( { items: [
          lemma,
          pos,
          languagesC,
          infoTypes,
          translations,
        ]}),
        new OO.ui.HorizontalLayout( { items: [
          generate,
        	run,
          limit,
          limitLabel,
          enpoints,
        ]}),
        queryDisplay
      ]
    }),{
			label: 'Select the suitable values to build your Wikidata Lexemes Query.',
			align: 'top'
		})
	]
);
$( "#lqg" ).append( fieldset.$element );

// Check data
var checkAvailableData = function(identity,element){
	// console.log('2',languages)
	console.log(identity+'a getElementId(): ',element.getElementId())
	console.log(identity+'b getData(): ',element.getData())
  console.log(identity+'c getValue(): ',element.getValue())
}

$('#lqg-lemma').on('focusout',function() {checkAvailableData(1,lemma);})
$('#lqg-languages').on('focusout',function() { checkAvailableData(2,languagesA);});