", {
class: "downloadBtns"
}).append($(yutils.svg.getElement(imgs.share))
.addClass("yashe_shareBtn")
@@ -27781,13 +27836,32 @@ var drawButtons = function(yashe){
}));
+ var wikiBtn = $("
", {
+ class: "downloadBtns"
+ }).append($(yutils.svg.getElement(imgs.tag))
+ .addClass("yashe_wikiBtn")
+ .attr('id','wikiBtn')
+ .attr("title", "Generate Wikidata Comments")
+ .click(function() {
+ !yashe.wikiFormatInProgress ?
+ yashe.wikiformat() :
+ yashe.stopWikiFormat();
+ }));
+
+
+
+
//Draw buttons
if(yashe.options.showShareButton){
- yashe.buttons.append(shareLinkBtn);
+ yashe.buttons.append(shareLinkBtn);
}
+ if(yashe.options.showWikiBtn){
+ yashe.buttons.append(wikiBtn);
+ }
+
if(yashe.options.showUploadButton){
yashe.buttons.append(uploadButton);
}
@@ -27820,14 +27894,15 @@ var drawButtons = function(yashe){
module.exports = {
drawButtons:drawButtons
}
-},{"./baseUtils.js":42,"./imgs.js":46,"codemirror":15,"jquery":16,"yasgui-utils":30}],44:[function(require,module,exports){
+},{"./baseUtils.js":43,"./imgs.js":47,"codemirror":15,"jquery":16,"yasgui-utils":30}],45:[function(require,module,exports){
// Symbols
const OPENING_PARENTHESIS = '(';
const CLOSING_PARENTHESIS = ')';
-const OPENING_CURLY_BRACKET= '{';
-const CLOSING_CURLY_BRACKET= '}';
-const OPENING_SQUARE_BRACKET= '[';
-const CLOSING_SQUARE_BRACKET= ']';
+const OPENING_CURLY_BRACKET = '{';
+const CLOSING_CURLY_BRACKET = '}';
+const OPENING_SQUARE_BRACKET = '[';
+const CLOSING_SQUARE_BRACKET = ']';
+const LOGICAL_OR = '|';
const SEMICOLON=';';
const DOLLAR = '$';
const AMPERSAND = '&';
@@ -27864,7 +27939,10 @@ module.exports ={
CLOSING_CURLY_BRACKET:CLOSING_CURLY_BRACKET,
OPENING_SQUARE_BRACKET:OPENING_SQUARE_BRACKET,
CLOSING_SQUARE_BRACKET:CLOSING_SQUARE_BRACKET,
+ LOGICAL_OR:LOGICAL_OR,
+ DOLLAR:DOLLAR,
SEMICOLON:SEMICOLON,
+ AMPERSAND:AMPERSAND,
EQUALS:EQUALS,
SHAPE_TYPE:SHAPE_TYPE,
@@ -27888,9 +27966,12 @@ module.exports ={
IMPORT_KEYWORD:IMPORT_KEYWORD,
START_KEYWORD:START_KEYWORD
}
-},{}],45:[function(require,module,exports){
-var CodeMirror = require("codemirror")
-const $ = require('jquery')
+},{}],46:[function(require,module,exports){
+const CodeMirror = require("codemirror");
+const $ = require('jquery');
+const wikiUtils = require('../utils/wikiUtils.js');
+let interact = require("./interactUtils.js");
+
"use strict";
var commentLines = function(yashe) {
@@ -28046,32 +28127,80 @@ var copyLineDown = function(yashe) {
};
- var wikiFormat = function(yashe){
+ var wikiFormat = async function(yashe){
+ if(yashe.hasErrors()){
+ interact.showErrAlertMsg(yashe);
+ return;
+ }
-
- for (var l = 7; l < yashe.lineCount(); ++l) {
- let lineTokens = yashe.getLineTokens(l);
- let nonWs = getNonWsLineTokens(lineTokens)
+ interact.startWikiFormat(yashe);
+ yashe.prettify();
+ let history = interact.disableEditor(yashe);
+ for (var l = 0; l < yashe.lineCount(); ++l) {
+ let lineTokens = getNonWsLineTokens(yashe.getLineTokens(l));
+ let valueSetSize = getValueSetSizeIfClosed(lineTokens);
+ let comments = ' # ';
for(let t in lineTokens){
+ if(!yashe.wikiFormatInProgress){
+ interact.stopWikiFormat(yashe,history);
+ return;
+ }
let token = lineTokens[t];
- //console.log(next)
- if(token.string.split(':')[0]=='wd' && !token.skip){
- console.log(token)
-
- //console.log({token:token,t:t,length:lineTokens.length,next:next})
- //console.log({line:l,col:{start:token.start,end:token.end},string:token.string})
-
- yashe.replaceRange(token.string+" #human \n",{line:l,ch:token.start},{line:l,ch:token.end})
-
-
-
-
+ if(wikiUtils.isWikidataPrefix(yashe,token)){
+ let entity = token.string.split(':')[1].toUpperCase();
+ let result = await wikiUtils.getEntity(entity,wikiUtils.wikidataEndpoint);
+ if(result.entities){
+ let entityData = wikiUtils.getEntityData(entity,result);
+ if(entityData){
+ comments += ' '+entityData.title;
+ valueSetSize--;
+ }
+ }
+ }
+
+ if(isLastToken(t,lineTokens) && comments!=' # '){
+ let endOfLine = lineTokens[lineTokens.length-1].end
+ yashe.replaceRange(comments,{line:l,ch:endOfLine},{line:l,ch:endOfLine})
+ if(yashe.hasErrors(yashe))yashe.undo();
+ //For some reason I'm not able to make codemirror scroll methods work, so I'm forcing the scroll with the cursor
+ yashe.setCursor({line:l+10,ch:token.start});
+ valueSetSize = 0;
+ comments = '';
}
}
+
}
+ interact.stopWikiFormat(yashe,history);
+ }
+
+ var isLastToken = function(token,tokens){
+ return token == tokens.length-1;
}
+ /**
+ * Gets an array of linetokens. If the line closes the valueSet ']' return its size, otherwise 0
+ * @param {Array} lineTokens
+ */
+ var getValueSetSizeIfClosed = function(lineTokens){
+ let open = false;
+ let close = false;
+ let decrement = true;
+ let size = lineTokens.reduce((acc,t)=>{
+ if(t.string=='[')open=true;
+ if(t.string==']')close=true;
+ if(t.type=='valueSet')acc++;
+ if(t.type=='variable-3')decrement=false;
+ if(t.type=='string-2')decrement=false;
+ return acc;
+ },1)
+
+ if(decrement)size--;
+ if(open && close)return size;
+ return 1;
+ }
+
+
var getNonWsLineTokens = function(lineTokens){
return lineTokens.reduce((acc,t)=>{
if(t.type!='ws')acc.push(t);
@@ -28079,27 +28208,17 @@ var copyLineDown = function(yashe) {
},[]);
}
- var getNextNonWSLineToken = function(yashe,lineTokens,lineIndex){
- let i = 1;
- let token = lineTokens[lineIndex+i];
- //console.log(token)
- while(token && token.type=='ws'){
- i++;
- token = lineTokens[lineIndex+i];
- }
- return token;
- }
-
module.exports = {
commentLines:commentLines,
copyLineUp: copyLineUp,
copyLineDown: copyLineDown,
doAutoFormat:doAutoFormat,
+ getNonWsLineTokens:getNonWsLineTokens,
wikiFormat:wikiFormat
};
-},{"codemirror":15,"jquery":16}],46:[function(require,module,exports){
+},{"../utils/wikiUtils.js":58,"./interactUtils.js":48,"codemirror":15,"jquery":16}],47:[function(require,module,exports){
"use strict";
module.exports = {
copy: '
',
@@ -28112,11 +28231,73 @@ module.exports = {
delete:'
',
theme:'
',
endpoint:'
',
+ tag:'
',
+ stop:'
'
};
-},{}],47:[function(require,module,exports){
+},{}],48:[function(require,module,exports){
+let yutils = require("yasgui-utils");
+let imgs = require("./imgs.js");
+let wikiNotification = $("
");
+
+var showErrAlertMsg = function(yashe){
+ wikiNotification
+ .show()
+ .text("I can't do that...Fix the errors before")
+ .appendTo($(yashe.getWrapperElement()));
+
+ setTimeout(() => {
+ wikiNotification.hide()
+ }, 3000);
+}
+
+var startWikiFormat = function(yashe){
+ yashe.wikiFormatInProgress = true;
+ $('#wikiBtn').attr("title", "STOP");
+ $('#wikiBtn').empty();
+ $('#wikiBtn').append($(yutils.svg.getElement(imgs.stop)));
+ $('#wikiBtn').removeClass("yashe_wikiBtn");
+ $('#wikiBtn').removeClass("yashe_wikiBtnAfter");
+ $('#wikiBtn').addClass("yashe_stopBtn");
+ wikiNotification.show().text("Adding Wikidata Comments").appendTo($(yashe.getWrapperElement()));
+}
+
+var stopWikiFormat = function(yashe,history){
+ yashe.wikiFormatInProgress = false;
+ setTimeout(() => { //Just to wait until the last comment is setted
+ $('#wikiBtn').attr("title", "Generate Wikidata Comments");
+ $('#wikiBtn').empty();
+ $('#wikiBtn').removeClass("yashe_stopBtn");
+ $('#wikiBtn').addClass("yashe_wikiBtnAfter");
+ $('#wikiBtn').append($(yutils.svg.getElement(imgs.tag)));
+ wikiNotification.hide();
+ yashe.prettify();
+ enableEditor(yashe,history);
+ }, 400);
+}
+
+var disableEditor = function(yashe){
+ yashe.setOption('readOnly',true);
+ return yashe.getHistory();
+}
+var enableEditor = function(yashe,history){
+ yashe.setHistory(history);
+ yashe.setOption('readOnly',false);
+}
+
+
+
+module.exports ={
+ startWikiFormat:startWikiFormat,
+ stopWikiFormat:stopWikiFormat,
+ enableEditor:enableEditor,
+ disableEditor:disableEditor,
+ showErrAlertMsg:showErrAlertMsg
+
+}
+},{"./imgs.js":47,"yasgui-utils":30}],49:[function(require,module,exports){
var CodeMirror = require("codemirror"), tokenUtils = require("./tokenUtils.js");
("use strict");
@@ -28236,7 +28417,7 @@ CodeMirror.registerHelper("fold", "prefix", function(cm, start) {
to: CodeMirror.Pos(prefixEndLine, prefixEndChar)
};
});
-},{"./tokenUtils.js":55,"codemirror":15}],48:[function(require,module,exports){
+},{"./tokenUtils.js":56,"codemirror":15}],50:[function(require,module,exports){
"use strict";
/**
* Append prefix declaration to list of prefixes in query window.
@@ -28346,21 +28527,23 @@ module.exports = {
removePrefixes: removePrefixes
};
-},{}],49:[function(require,module,exports){
+},{}],51:[function(require,module,exports){
class Node{
- constructor(constraints,triples,comment='',emptyBrackets,afterTriples=[],finalParenthesis=''){
+ constructor(constraints,triples,comment='',emptyBrackets,afterTriples=[],finalParenthesis='',multiElementOneOf=false){
this.constraints = constraints;
this.triples = triples;
- this.comment = comment; //Comment at the end
- this.emptyBrackets = emptyBrackets; //ej: schema:name {};
- this.afterTriples= afterTriples; // Whatever after {}
- this.finalParenthesis = finalParenthesis; //Is an
+ this.comment = comment; //Comment at the end
+ this.emptyBrackets = emptyBrackets; //ej: schema:name {};
+ this.afterTriples= afterTriples; // Whatever after {}
+ this.finalParenthesis = finalParenthesis;
+ this.hasAleardyAComment = false; //This is used in the methor getSemicolonIfNeeded due not to set the comment again if it has been already seted
+ this.multiElementOneOf = multiElementOneOf;
}
- toString(longest,isTriple,indent=1,isLastTriple=false){
+ toString(longest=0,isTriple,indent=1,isLastTriple=false){
let str = EMPTY_STRING;
- let constraints=this.getConstraints(longest,indent);
+ let constraints=this.getConstraints(this.constraints,longest,indent);
str+=constraints.str;
str+=this.getTriplesString(indent,constraints.tripleComment,isTriple,isLastTriple);
@@ -28368,22 +28551,32 @@ class Node{
}
//This method could be prettier
- getConstraints(longest,indent){
- let valueSetSize = getValueSetSize(this.constraints);
+ getConstraints(constraints,longest,indent){
+ let valueSetSize = getValueSetSize(constraints);
let forceSeparator = false;
let valueSet = false;
- return this.constraints.reduce((acc,token,index)=>{
- let nexToken = this.constraints[index+1];
- let separator = getSeparatorIfNeeded(index,token,nexToken,this.triples.length,longest,this.constraints,this.emptyBrackets);
+ let previousToken;
+ return constraints.reduce((acc,token,index)=>{
+
+ if(token.skip)return acc;
+
+ let nexToken = constraints[index+1];
+ let separator = getSeparatorIfNeeded(index,token,nexToken,this.triples.length,longest,constraints,this.emptyBrackets);
if(token.type==COMMENT_TYPE){
-
- if(valueSet){
+ //console.log({previousToken:previousToken.string,token:token.string,nexToken:nexToken})
+ if(previousToken && previousToken.string=='[' && valueSetSize>2){
+ acc.str+= token.string;
+ }else if(nexToken && nexToken.string=='[' && valueSetSize>2){
+ acc.str+= '[ '+token.string;
+ nexToken.skip = true;
+ }else if(valueSet){
+
acc.str+= token.string;
- acc.str += this.getClosingValueSetIfNeeded(nexToken,valueSet,indent);
+ acc.str+= this.getClosingValueSetIfNeeded(nexToken,valueSet,indent);
}else{
forceSeparator = this.startsWithComment(index);//If it's a comment before the constraints skip it
- acc.tripleComment+= this.getTripleComment(forceSeparator,token); //If not, add it to the finish of the line
+ acc.tripleComment = this.getTripleComment(forceSeparator,token) + acc.tripleComment ; //If not, add it to the finish of the line
}
@@ -28392,13 +28585,15 @@ class Node{
index = this.decrementIndexIfNeeded(forceSeparator);
separator = this.modifySeparatorIfNeeded(separator,nexToken,valueSetSize);
- valueSet = this.isLongValueSet(token,valueSetSize);
- acc.str += this.getOpeningValueSetIfNeeded(valueSet,indent);
+ valueSet = this.isValueSet(token,valueSetSize);
+ acc.str += this.getOpeningValueSetIfNeeded(valueSet,indent,nexToken);
acc.str += this.getWhiteSpaceIfNeeded(token);
acc.str += this.getTokenString(token,separator);
acc.str += this.getClosingValueSetIfNeeded(nexToken,valueSet,indent);
}
+
+ previousToken = token;
return acc;
},{
str:EMPTY_STRING,
@@ -28410,10 +28605,9 @@ class Node{
getTriplesString(indent,tripleComment,isTriple,isLastTriple){
let str = EMPTY_STRING;
-
str += this.getSubTriplesStrIfNeeded(indent,tripleComment,isTriple);
str += this.getEmptyBracketsIfNeeded();
- str += this.getAfterTriplesStr();
+ str += this.getAfterTriplesStr(indent);
str += this.getSemicolonIfNeeded(isTriple,isLastTriple,tripleComment);
str += this.getFinalParenthesisIfNeeded();
@@ -28425,12 +28619,18 @@ class Node{
let str = EMPTY_STRING;
if(this.triples.length>0){
let linebreak = LINE_BREAK;
- if(isTriple && this.triples.length==1){
- if(tripleComment==EMPTY_STRING){// If there is any comment after '{' we need to force the breakline
- linebreak = EMPTY_STRING;
- indent--;
+ // This is off at this moment
+ /* if(isTriple){
+ if(this.triples.length==1) {
+ console.log('p')
+ // If there isn't any comment after '{' don't force the breakline
+ if(tripleComment==EMPTY_STRING && !this.hasComments(this.triples[0])){
+ linebreak = EMPTY_STRING;
+ indent--;
+ }
}
- }
+ } */
+
str+=this.getSubTriplesStr(indent,tripleComment,linebreak);
}
return str;
@@ -28438,30 +28638,39 @@ class Node{
getSubTriplesStr(indent,tripleComment,linebreak){
+ this.hasAleardyAComment=true;
let str=OPENING_CURLY_BRACKET+tripleComment+linebreak;
+ if(tripleComment!='')tripleComment='';
this.triples.map((t,index)=>{
let currentLongest = getLongestTConstraint(this.triples);
str+= getIndent(indent);
str+= t.toString(currentLongest,true,indent+1,this.isLastTriple(index));
- str+= WHITE_SPACE+t.comment +linebreak;
+ str+= WHITE_SPACE + t.comment +linebreak;
})
return str + getIndent(indent-1)+CLOSING_CURLY_BRACKET;
}
- getAfterTriplesStr(){
+ getAfterTriplesStr(indent){
let str = EMPTY_STRING;
- if(this.afterTriples.length>0)str+=WHITE_SPACE;
- return this.afterTriples.reduce((acc,a)=>{
- return acc+=a.string+WHITE_SPACE;
- },str);
+ if(this.afterTriples.length>0){
+ str+=WHITE_SPACE;
+ }else{
+ return '';
+ }
+ let constraints = this.getConstraints(this.afterTriples,0,indent);
+ return constraints.str+constraints.tripleComment;
}
+
+
getSemicolonIfNeeded(isTriple,isLastTriple,tripleComment){
let str = EMPTY_STRING;
if(isTriple){
- if(!isLastTriple)str+=SEMICOLON;
- str+=tripleComment;
+ if(!isLastTriple){
+ if(!this.multiElementOneOf)str+=SEMICOLON;
+ }
+ if(!this.hasAleardyAComment)str+=tripleComment;
}
return str;
}
@@ -28497,7 +28706,7 @@ class Node{
return token.string+separator;
}
- isLongValueSet(token,valueSetSize){
+ isValueSet(token,valueSetSize){
return token.type==VALUESET_TYPE && valueSetSize>VALUESET_LINE_LIMIT;
}
@@ -28507,7 +28716,7 @@ class Node{
return index;
}
- getOpeningValueSetIfNeeded(valueSet,indent){
+ getOpeningValueSetIfNeeded(valueSet,indent,nexToken){
if(valueSet)
return LINE_BREAK+getIndent(indent);
return EMPTY_STRING;
@@ -28534,7 +28743,14 @@ class Node{
}
+ hasComments(triple){
+ return triple.constraints.reduce((acc,c)=>{
+ if(c.type=='comment' && c.start)acc = true; //c.start just to check it's a real comment token
+ return acc;
+ },false)
+ }
+
}
@@ -28549,7 +28765,7 @@ let {
WHITE_SPACE,
EMPTY_STRING,
VALUESET_LINE_LIMIT,
- EMPTY_BRACKETS,
+ EMPTY_BRACKETS
} = require('./printUtils.js');
let {
@@ -28564,8 +28780,7 @@ let {
AND_KEYWORD,
OR_KEYWORD
} = require('../constUtils.js');
-
-},{"../constUtils.js":44,"./printUtils.js":51}],50:[function(require,module,exports){
+},{"../constUtils.js":45,"./printUtils.js":53}],52:[function(require,module,exports){
function prettify(yashe){
// Save the value before the prettify it
@@ -28576,39 +28791,47 @@ function prettify(yashe){
let tokens = getTokens(yashe);
// Objects
- let firstComments = getFirstComments(tokens);
- let directivesAndStarts = getDirectivesAndStarts(tokens);
+ let initialComments = getFirstComments(tokens);
+ let initialDirectivesAndStarts = getInitialDirectivesAndStarts(tokens);
let shapes = getShapes(tokens);
+ console.log(shapes)
// Strings
- let directivesStr = getDirectivesAndStartsStr(directivesAndStarts);
+ let initialDirectivesAndStartsStr = getDirectivesAndStartsStr(initialDirectivesAndStarts);
let shapesStr = getShapesStr(shapes);
- let prettified = firstComments+directivesStr+shapesStr;
+ let prettified = initialComments+initialDirectivesAndStartsStr+shapesStr;
// Is there any change?
// It is true that without this check the user
// wouldn't appreciate the difference but yashe
// would be doing operations that would appear
- // in the undo stack
+ // in the undo/redo stack
if(previousValue!=prettified){
yashe.setValue(prettified) ;
+ prettifyComments();
setCursor(yashe,cursorPosition);
}
+
}
function getShapes(tokens){
return getShapesTokens(tokens).reduce((acc,shapeTokens)=>{
let nodes = getNodes(shapeTokens);
let comments = getCommentsAfterShape(shapeTokens);
-
- acc.push(new Shape(nodes,comments));
+ let prefixes = getPrefixesAfterShape(shapeTokens);
+
+ acc.push(new Shape(nodes,comments,prefixes));
return acc;
},[])
}
+function getPrefixesAfterShape(shapeTokens){
+ return getDirectivesAndStartsStr(getDirectivesAndStarts(shapeTokens.reverse()));
+}
+
function getNodes(shapeTokens){
- return getSlots(shapeTokens).reduce((acc,slot,index)=>{
+ return getSlots(shapeTokens).reduce((acc,slot)=>{
let constraints = getBeforeTriplesTokens(slot);
let triples = getTriples(getTripleTokens(slot));
let paranthesis = hasFinalParenthesis(slot);
@@ -28636,13 +28859,17 @@ function hasFinalParenthesis(slot){
function getCommentsAfterShape(shapeTokens){
let i = 0;
return shapeTokens.reverse().reduce((acc,t,index)=>{
+
if(t.type==COMMENT_TYPE && index == i){ //index == i is needed in order not to take comments after a differtent token (CLOSING_CURLY_BRACKET)
- acc.push(t);
+ if(!isDirective(shapeTokens[index+1])){//check that it's not a directive comment
+ acc.push(t);
+ }
i++;
}
+
if(isDirective(t) || isStart(t,shapeTokens[index+1])){
- i++;
+ i++
}
return acc;
@@ -28660,17 +28887,18 @@ function getTriples(tokens) {
if(token.skip) return acc; //Is a comment that is part of the previous triple
singleTriple.push(token);
-
- if(isFinishOfTriple(tokens,token,index,finish)){
+ let multiElementOneOf = isMultiElementOneOf(token);
+ if(isFinishOfTriple(tokens,token,index,finish) || multiElementOneOf){
if(singleTriple.length>1){
+ console.log(singleTriple)
let before = getBeforeTriplesTokens(singleTriple);
let tripleTokens = getTripleTokens(singleTriple);
let subTriples = getTriples(tripleTokens);
- let after = getAfterTripleTokens(singleTriple);
+ let after = getAfterTripleTokens(singleTriple,multiElementOneOf);
let comment = getComentsAfterToken(token,tokens,index); //We want the tokens after the Triple
let emptyBrackets = start && subTriples.length==0;
-
- acc.push(new Node(before,subTriples,comment,emptyBrackets,after));
+
+ acc.push(new Node(before,subTriples,comment,emptyBrackets,after,'',multiElementOneOf));
start=false;
}
singleTriple = [];
@@ -28689,10 +28917,11 @@ function getTriples(tokens) {
},[])
}
-function getAfterTripleTokens(tokens){
+
+function getAfterTripleTokens(tokens,multiElementOneOf){
let start=false;
let open = 0;
- return tokens.reduce((acc,t)=>{
+ let after = tokens.reduce((acc,t)=>{
if(open == 0 && start){
if(t.string != SEMICOLON
@@ -28711,6 +28940,9 @@ function getAfterTripleTokens(tokens){
return acc;
},[])
+
+ if(after.length==0 && multiElementOneOf)after.push(tokens[tokens.length-1]);
+ return after;
}
@@ -28725,7 +28957,7 @@ function getBeforeTriplesTokens(tokens){
start = false;
}
- if(index == tokens.length-1 && t.string!='.')start=false; //Break condition 2
+ if(index == tokens.length-1 && t.string!='.' && t.string!=']')start=false; //Break condition 2 -> If it's the last token break unless it's a . or ] which we want it
if(start){
acc.push(t);
@@ -28816,10 +29048,15 @@ function getTokens(){
}
+function getInitialDirectivesAndStarts(tokens){
+ return getDirectivesAndStarts(tokens,SHAPE_TYPE);
+}
+
+
/**
Sorry Acebal
*/
-function getDirectivesAndStarts(tokens){
+function getDirectivesAndStarts(tokens,breakCondition){
let prefix = {};
let base = {};
let importt = {};
@@ -28827,7 +29064,13 @@ function getDirectivesAndStarts(tokens){
let baseCont = 0;
let importCont = 0;
let startCont = 0;
+ let stop = false;
return tokens.reduce((acc,t,index)=>{
+
+ if(stop)return acc;
+ if(t.type == breakCondition)stop=true;
+
+
if(t.string.toUpperCase()==PREFIX_KEYWORD){
prefix = {};
prefix.comments = getComentsAfterToken(t,tokens,index);
@@ -28945,6 +29188,7 @@ function getFirstComments(tokens){
}
function isDirective(token) {
+ if(!token)return false;
if( token.string.toUpperCase()==PREFIX_KEYWORD
|| token.string.toUpperCase()==BASE_KEYWORD
|| token.string.toUpperCase()==IMPORT_KEYWORD
@@ -28995,17 +29239,58 @@ function setCursor(yashe,position){
}
}
-function isCursorToken(token1,token2,line){
- return token1.start == token2.start
- && token1.end == token2.end
- && token1.string == token2.string
- && token1.type == token2.type
- && line == token2.line;
+
+function prettifyComments(){
+ let longest = getLongestCommentedLine();
+ let history = yashe.getHistory();
+ for (var l = 0; l < yashe.lineCount(); ++l) {
+ let lineTokens = formatUtils.getNonWsLineTokens(yashe.getLineTokens(l));
+ if(!hasOnlyComments(lineTokens)){
+ lineTokens.map(t=>{
+ if(t.type == 'comment') {
+ yashe.replaceRange(printUtils.getSeparator(longest-t.start)+t.string,{line:l,ch:t.start},{line:l,ch:t.end})
+ }
+ });
+ }
+ }
+ yashe.setHistory(history);
}
-function isStart(token,previousToken) {
- if((token.string.toUpperCase()==START_KEYWORD && token.type == KEYWORD_TYPE)
- || (token.string== EQUALS && token.type == PUNC_TYPE)
+
+function getLongestCommentedLine(){
+ let longest = 0;
+ for (var l = 0; l < yashe.lineCount(); ++l) {
+ let lineTokens = formatUtils.getNonWsLineTokens(yashe.getLineTokens(l));
+ let lastLineToken = lineTokens[lineTokens.length-1];
+ if(lastLineToken)
+ if(lastLineToken.start>longest)
+ longest = lastLineToken.start;
+ }
+ return longest;
+}
+
+/**
+ * Returns true if the line has onlyComments
+ */
+function hasOnlyComments(lineTokens){
+ return lineTokens.reduce((acc,t)=>{
+ if(t.type!='comment')acc=false;
+ return acc;
+ },true);
+}
+
+
+function isCursorToken(token1,token2,line){
+ return token1.start == token2.start
+ && token1.end == token2.end
+ && token1.string == token2.string
+ && token1.type == token2.type
+ && line == token2.line;
+}
+
+function isStart(token,previousToken) {
+ if((token.string.toUpperCase()==START_KEYWORD && token.type == KEYWORD_TYPE)
+ || (token.string== EQUALS && token.type == PUNC_TYPE)
|| (token.type == SHAPE_REF_TYPE && previousToken && previousToken.string == EQUALS)) return true;
return false;
}
@@ -29020,6 +29305,10 @@ function getNonWsTokens(tokens){
})
}
+function isMultiElementOneOf(token){
+ return token.string == LOGICAL_OR;
+}
+
module.exports = {
prettify:prettify,
@@ -29028,6 +29317,7 @@ module.exports = {
let Shape = require('./shape.js');
let Node = require('./node.js');
+let formatUtils = require('../formatUtils.js');
let {
getLongestPrefix,
getSeparator,
@@ -29038,6 +29328,7 @@ let {
OPENING_CURLY_BRACKET,
CLOSING_CURLY_BRACKET,
CLOSING_PARENTHESIS,
+ LOGICAL_OR,
SEMICOLON,
EQUALS,
@@ -29059,7 +29350,9 @@ let {
OR_KEYWORD,
START_KEYWORD
} = require('../constUtils.js');
-},{"../constUtils.js":44,"./node.js":49,"./printUtils.js":51,"./shape.js":52}],51:[function(require,module,exports){
+const printUtils = require('./printUtils.js');
+
+},{"../constUtils.js":45,"../formatUtils.js":46,"./node.js":51,"./printUtils.js":53,"./shape.js":54}],53:[function(require,module,exports){
const VALUESET_LINE_LIMIT = 2; // Sets the máximun number of values inside a valueSet
const LINE_BREAK = '\n';
const WHITE_SPACE = ' ';
@@ -29094,7 +29387,7 @@ function getIndent(tab) {
function getLongestPrefix(prefixes){
return prefixes.reduce((acc,p) =>{
- if(p.alias.string.length>acc)acc=p.alias.string.length;
+ if(p.alias && p.alias.string.length>acc)acc=p.alias.string.length;
return acc;
},0);
}
@@ -29113,6 +29406,7 @@ function getLongestTConstraint(triples){
}
+
function needsSeparator(index,token,nexToken,triplesLenght,constraints,emptyBrackets){
if(isJustEmptyBrackets(triplesLenght,emptyBrackets,constraints))return true;
return index==0
@@ -29178,8 +29472,11 @@ function getDirectivesAndStartsStr(directives) {
function getPrefixesStr(prefixes,keyword){
return prefixes.reduce((acc,p)=>{
- let dif = getLongestPrefix(prefixes) - p.alias.string.length;
- return acc+= keyword+p.alias.string+getSeparator(dif)+p.iri.string+p.comments+'\n';
+ if(p.alias){
+ let dif = getLongestPrefix(prefixes) - p.alias.string.length;
+ return acc+= keyword+p.alias.string+getSeparator(dif)+p.iri.string+p.comments+'\n';
+ }
+ return acc;
},'');
}
@@ -29193,12 +29490,12 @@ function getConcreteDirectiveStr(directives,keyword) {
function getStartsStr(starts) {
return starts.reduce((acc,s)=>{
return acc+=s+"\n";
- },"")+'\n';
+ },"");
}
function getShapesStr(shapes) {
return shapes.reduce((acc,s)=>{
- return acc+=s.toString()+"\n\n";
+ return acc+='\n'+s.toString()+'\n';
},'');
}
@@ -29242,12 +29539,13 @@ let {
OR_KEYWORD
} = require('../constUtils.js');
-},{"../constUtils.js":44}],52:[function(require,module,exports){
+},{"../constUtils.js":45}],54:[function(require,module,exports){
class Shape{
- constructor(nodes,comments=[]){
+ constructor(nodes,comments=[],directivesAndStarts){
this.nodes = nodes;
this.comments = comments;
+ this.directivesAndStarts = directivesAndStarts;
}
getCommentsStr(){
@@ -29256,131 +29554,22 @@ class Shape{
},"");
}
+ getDirectivesAndStartsStr(){
+ let str = '';
+ if(this.directivesAndStarts.trim()!='')
+ str = '\n\n'+this.directivesAndStarts;
+ return str;
+ }
+
toString(){
return this.nodes.reduce((acc,n)=>{
- return acc+=n.toString(0) + this.getCommentsStr();
+ return acc+=n.toString() + this.getCommentsStr() + this.getDirectivesAndStartsStr();
},"");
}
}
module.exports = Shape;
-},{}],53:[function(require,module,exports){
-const ENTITY_TYPES = {
- 'http://www.wikidata.org/prop/direct/': 'property',
- 'http://www.wikidata.org/prop/direct-normalized/': 'property',
- 'http://www.wikidata.org/prop/': 'property',
- 'http://www.wikidata.org/prop/novalue/': 'property',
- 'http://www.wikidata.org/prop/statement/': 'property',
- 'http://www.wikidata.org/prop/statement/value/': 'property',
- 'http://www.wikidata.org/prop/statement/value-normalized/': 'property',
- 'http://www.wikidata.org/prop/qualifier/': 'property',
- 'http://www.wikidata.org/prop/qualifier/value/': 'property',
- 'http://www.wikidata.org/prop/qualifier/value-normalized/': 'property',
- 'http://www.wikidata.org/prop/reference/': 'property',
- 'http://www.wikidata.org/prop/reference/value/': 'property',
- 'http://www.wikidata.org/prop/reference/value-normalized/': 'property',
- 'http://www.wikidata.org/wiki/Special:EntityData/': 'item',
- 'http://www.wikidata.org/entity/': 'item'
-};
-
-const NAMESPACE_SHORTCUTS = {
- wikibase: 'http://wikiba.se/ontology#',
- wd: 'http://www.wikidata.org/entity/',
- wdt: 'http://www.wikidata.org/prop/direct/',
- wdtn: 'http://www.wikidata.org/prop/direct-normalized/',
- wds: 'http://www.wikidata.org/entity/statement/',
- p: 'http://www.wikidata.org/prop/',
- wdref: 'http://www.wikidata.org/reference/',
- wdv: 'http://www.wikidata.org/value/',
- ps: 'http://www.wikidata.org/prop/statement/',
- psv: 'http://www.wikidata.org/prop/statement/value/',
- psn: 'http://www.wikidata.org/prop/statement/value-normalized/',
- pq: 'http://www.wikidata.org/prop/qualifier/',
- pqv: 'http://www.wikidata.org/prop/qualifier/value/',
- pqn: 'http://www.wikidata.org/prop/qualifier/value-normalized/',
- pr: 'http://www.wikidata.org/prop/reference/',
- prv: 'http://www.wikidata.org/prop/reference/value/',
- prn: 'http://www.wikidata.org/prop/reference/value-normalized/',
- wdno: 'http://www.wikidata.org/prop/novalue/',
- wdata: 'http://www.wikidata.org/wiki/Special:EntityData/'
- }
-
-const WIKIDATA_ENDPOINT= 'https://www.wikidata.org/w/'
-
-
-
-var getEndPoint = function(yashe,prefixName){
-
- let definedPrefixex = yashe.getDefinedPrefixes();
- let endpoint = null;
- Object.keys(definedPrefixex).map(p =>{
- if(p==prefixName){
- if(definedPrefixex[p].includes('/wiki/')){
- endpoint = definedPrefixex[p].replace('http://','https://').split('/wiki/')[0]+'/w/';
- }else{
- Object.keys(ENTITY_TYPES).map(pref=>{
- if(pref === definedPrefixex[p]){
- endpoint = WIKIDATA_ENDPOINT;
- }
- });
- }
- }
- })
-
- return endpoint;
-}
-
-
-var isWikidataEntitiesPrefix = function(yashe,prefixName){
-
- var definedPrefixex = yashe.getDefinedPrefixes()
- var iriPrefix
-
- //Gets de IRI of the prefix from the defined
- for (const prop in definedPrefixex) {
- if(prop === prefixName)
- iriPrefix = definedPrefixex[prop]
- }
-
-
- //Compare iriPrefix with the valid wikidata entities prefixes
- for(const pref in ENTITY_TYPES){
- if(ENTITY_TYPES[pref] === 'item' && pref == iriPrefix)
- return true
- }
- return false
-}
-
-var isWikidataPropertiesPrefix = function(yashe,prefixName){
-
- var definedPrefixex = yashe.getDefinedPrefixes()
- var iriPrefix
-
- //Gets de IRI of the prefix from the defined
- for (const prop in definedPrefixex) {
- if(prop === prefixName)
- iriPrefix = definedPrefixex[prop]
- }
-
- //Compare iriPrefix with the valid wikidata properties prefixes
- for(const pref in ENTITY_TYPES){
- if(ENTITY_TYPES[pref] === 'property' && pref == iriPrefix)
- return true
- }
- return false
-}
-
-
-module.exports = {
-
- entityTypes:ENTITY_TYPES,
- namespaceShortCuts: NAMESPACE_SHORTCUTS,
- getEndPoint:getEndPoint,
- isWikidataEntitiesPrefix:isWikidataEntitiesPrefix,
- isWikidataPropertiesPrefix:isWikidataPropertiesPrefix
-
-}
-},{}],54:[function(require,module,exports){
+},{}],55:[function(require,module,exports){
"use strict";
var $ = require("jquery"),
yutils = require("yasgui-utils"),
@@ -29394,8 +29583,12 @@ var checkSyntax = function(yashe) {
resetValues(yashe);
var state = null;
- let openTokensCounter = 0;
- let closedTokensCounter = 0;
+ let openBracketsCounter = 0;
+ let closedBracketsCounter = 0;
+ let openParenthesisCounter = 0;
+ let closedParenthesisCounter = 0;
+ let openSquareBracketsCounter = 0;
+ let closedSquareBracketsCounter = 0;
for (var l = 0; l < yashe.lineCount(); ++l) {
var precise = false;
@@ -29449,6 +29642,7 @@ var checkSyntax = function(yashe) {
warningEl.className = "parseErrorIcon";
yashe.setGutterMarker(l, "gutterErrorBar", warningEl);
+
yashe.queryValid = false;
return false;
}
@@ -29456,25 +29650,54 @@ var checkSyntax = function(yashe) {
let lineTokens = yashe.getLineTokens(l);
for(let t in lineTokens){
let token = lineTokens[t];
- //This is only necessary to verify the if the last '}' is missing (See #104)
+
if(token.string=='{'){
- openTokensCounter++;
+ openBracketsCounter++;
}
if(token.string=='}'){
- closedTokensCounter++;
+ closedBracketsCounter++;
+ }
+
+ if(token.string=='('){
+ openParenthesisCounter++;
+ }
+ if(token.string==')'){
+ closedParenthesisCounter++;
}
+
+ if(token.string=='['){
+ openSquareBracketsCounter++;
+ }
+ if(token.string==']'){
+ closedSquareBracketsCounter++;
+ }
+
}
updateShapesAndPrefixes(yashe,l);
}
- //Is last '}' missing? (See #104)
- if(openTokensCounter != closedTokensCounter){
+ //Is last '}' missing? (See #104 https://github.com/weso/YASHE/issues/104)
+ if(openBracketsCounter != closedBracketsCounter){
setError(yashe.lastLine(),"This line is invalid. Expected: '}'",yashe)
yashe.queryValid = false;
return false;
}
+ //Is last ')' missing? (See #150 https://github.com/weso/YASHE/issues/150)
+ if(openParenthesisCounter != closedParenthesisCounter){
+ setError(yashe.lastLine(),"This line is invalid. Expected: ')'",yashe)
+ yashe.queryValid = false;
+ return false;
+ }
+
+ //Is last ']' missing? (See #163 https://github.com/weso/YASHE/issues/163)
+ if(openSquareBracketsCounter != closedSquareBracketsCounter){
+ setError(yashe.lastLine(),"This line is invalid. Expected: ']'",yashe)
+ yashe.queryValid = false;
+ return false;
+ }
+
if(!checkPrefixes(yashe))return false;
@@ -29502,8 +29725,7 @@ var checkSyntax = function(yashe) {
let token = lineTokens[t];
- if(token.type=='string-2' ||
- token.type=='constraint'){
+ if(token.type=='string-2'|| (token.type=='constraint' && token.string.includes(":"))){
yashe.usedPrefixes.push({
alias:token.string.split(":")[0]+':',
line:l });
@@ -29549,7 +29771,6 @@ var checkSyntax = function(yashe) {
}
-
/**
* Check if the ShapeRefs are defined
@@ -29602,11 +29823,19 @@ var checkSyntax = function(yashe) {
yashe.setGutterMarker(line, "gutterErrorBar", warningEl);
}
+
+ var reCheckSyntax = function(yashe){
+ setTimeout(() => {
+ checkSyntax(yashe);
+ }, 400);
+ }
+
module.exports = {
- checkSyntax:checkSyntax
+ checkSyntax:checkSyntax,
+ reCheckSyntax:reCheckSyntax
};
-},{"./imgs.js":46,"./tooltipUtils.js":56,"jquery":16,"yasgui-utils":30}],55:[function(require,module,exports){
+},{"./imgs.js":47,"./tooltipUtils.js":57,"jquery":16,"yasgui-utils":30}],56:[function(require,module,exports){
"use strict";
/**
* @param yashe {doc}
@@ -29652,10 +29881,10 @@ module.exports = {
getNextNonWsToken: getNextNonWsToken
};
-},{}],56:[function(require,module,exports){
+},{}],57:[function(require,module,exports){
"use strict";
var $ = require("jquery"),
- rdfUtils = require('./rdfUtils.js')
+ wikiUtils = require('./wikiUtils.js')
/**
* Write our own tooltip, to avoid loading another library for just this functionality. For now, we only use tooltip for showing parse errors, so this is quite a tailored solution
@@ -29711,13 +29940,13 @@ var triggerTooltip = function(yashe, e) {
var wikiElement = token.split(':')[1]
if(wikiElement!== undefined && wikiElement!== ''){
- let endpoint = rdfUtils.getEndPoint(yashe,prefixName);
+ let endpoint = wikiUtils.getEndPoint(yashe,prefixName);
if(endpoint!=null){
- checkEntity(wikiElement,endpoint)
+ wikiUtils.getEntity(wikiElement,endpoint)
.done((data)=>{loadTooltip(yashe,data,wikiElement,posX,posY)})
.fail(
()=>{
- checkEntity(wikiElement,endpoint.replace('/w/','/wiki/'))
+ wikiUtils.getEntity(wikiElement,endpoint.replace('/w/','/wiki/'))
.done((data)=>{loadTooltip(yashe,data,wikiElement,posX,posY)})
});
}
@@ -29726,42 +29955,9 @@ var triggerTooltip = function(yashe, e) {
}
var loadTooltip = function(yashe,data,wikiElement,posX,posY){
- if(!data.error){
-
- var userLang;
- var entity = '';
- var description=''
- var theme;
- //Gets the preference languaje from the navigator
- userLang = (navigator.language || navigator.userLanguage).split("-")[0]
-
-
- var content = data.entities[wikiElement.toUpperCase()]
-
- //Check if the property/entity exist
- if(!content.labels)return;
-
- //Some properties and entities are only avalible in English
- //So if they do not exist we take it in English
- if(content.labels[userLang] && content.descriptions[userLang]){
-
- entity = content.labels[userLang].value +' ('+wikiElement+')'
- description = content.descriptions[userLang].value
-
- }else{
-
- let lb = content.labels['en'];
- let desc = content.descriptions['en'];
- if(lb){
- entity = lb.value +' ('+wikiElement+')';
- }
- if(desc){
- description = desc.value
- }
-
- }
-
- theme = yashe.getOption('theme');
+ var entityData = wikiUtils.getEntityData(wikiElement,data);
+ if(entityData && entityData.title!=''){
+ let theme = yashe.getOption('theme');
let cssStyle = themeStyles['default'];
if(theme=='dark'){
cssStyle = themeStyles['dark'];
@@ -29779,23 +29975,12 @@ var loadTooltip = function(yashe,data,wikiElement,posX,posY){
.append(
$('