@@ -13,7 +13,7 @@ type ExampleQuery = {
1313
1414interface VoidDict {
1515 [ key : string ] : {
16- [ key : string ] : string [ ] ;
16+ [ key : string ] : string [ ] ;
1717 } ;
1818}
1919
@@ -252,27 +252,29 @@ export class SparqlEditor extends HTMLElement {
252252 // Not perfect, but we can't parse the whole query with SPARQL.js since it's no fully written yet
253253 // And it would throw an error if the query is not valid
254254 const subj = getSubjectForCursorPosition ( yasqe . getValue ( ) , cursor . line , cursor . ch ) ;
255- const subjTypes = extractAllSubjectsAndTypes ( yasqe . getValue ( ) )
255+ const subjTypes = extractAllSubjectsAndTypes ( yasqe . getValue ( ) ) ;
256256 // console.log(hints)
257257 if ( subj && subjTypes . has ( subj ) ) {
258258 const types = subjTypes . get ( subj ) ;
259259 if ( types ) {
260260 // console.log("Types", types)
261- const filteredHints = new Set ( )
261+ const filteredHints = new Set ( ) ;
262262 types . forEach ( typeCurie => {
263263 const propSet = new Set ( Object . keys ( this . voidDescription [ this . curieToUri ( typeCurie ) ] ) ) ;
264264 // console.log(propSet)
265- hints . filter ( ( obj : any ) => {
266- // console.log(this.curieToUri(obj.text))
267- return propSet . has ( this . curieToUri ( obj . text ) . replace ( / ^ < | > $ / g, '' ) )
268- } ) . forEach ( ( obj : any ) => {
269- filteredHints . add ( obj )
270- } )
265+ hints
266+ . filter ( ( obj : any ) => {
267+ // console.log(this.curieToUri(obj.text))
268+ return propSet . has ( this . curieToUri ( obj . text ) . replace ( / ^ < | > $ / g, "" ) ) ;
269+ } )
270+ . forEach ( ( obj : any ) => {
271+ filteredHints . add ( obj ) ;
272+ } ) ;
271273 } ) ;
272- return Array . from ( filteredHints )
274+ return Array . from ( filteredHints ) ;
273275 }
274276 }
275- return hints
277+ return hints ;
276278 } ,
277279 } ;
278280
@@ -354,20 +356,16 @@ WHERE {
354356 json . results . bindings . forEach ( ( b : any ) => {
355357 // clsList.push(b.class.value);
356358 if ( ! ( b [ "class1" ] [ "value" ] in this . voidDescription ) ) {
357- this . voidDescription [ b [ "class1" ] [ "value" ] ] = { }
359+ this . voidDescription [ b [ "class1" ] [ "value" ] ] = { } ;
358360 }
359361 if ( ! ( b [ "prop" ] [ "value" ] in this . voidDescription [ b [ "class1" ] [ "value" ] ] ) ) {
360- this . voidDescription [ b [ "class1" ] [ "value" ] ] [ b [ "prop" ] [ "value" ] ] = [ ]
362+ this . voidDescription [ b [ "class1" ] [ "value" ] ] [ b [ "prop" ] [ "value" ] ] = [ ] ;
361363 }
362364 if ( "class2" in b ) {
363- this . voidDescription [ b [ "class1" ] [ "value" ] ] [ b [ "prop" ] [ "value" ] ] . push (
364- b [ "class2" ] [ "value" ]
365- )
365+ this . voidDescription [ b [ "class1" ] [ "value" ] ] [ b [ "prop" ] [ "value" ] ] . push ( b [ "class2" ] [ "value" ] ) ;
366366 }
367367 if ( "datatype" in b ) {
368- this . voidDescription [ b [ "class1" ] [ "value" ] ] [ b [ "prop" ] [ "value" ] ] . push (
369- b [ "datatype" ] [ "value" ]
370- )
368+ this . voidDescription [ b [ "class1" ] [ "value" ] ] [ b [ "prop" ] [ "value" ] ] . push ( b [ "datatype" ] [ "value" ] ) ;
371369 }
372370 } ) ;
373371 } catch ( error ) {
@@ -528,7 +526,7 @@ SELECT DISTINCT ?sq ?comment ?query WHERE {
528526 // Function to convert CURIE to full URI using the prefix map
529527 curieToUri ( curie : string ) {
530528 if ( / ^ [ a - z A - Z ] [ a - z A - Z 0 - 9 ] * : [ a - z A - Z ] [ a - z A - Z 0 - 9 ] * $ / . test ( curie ) ) {
531- const [ prefix , local ] = curie . split ( ':' ) ;
529+ const [ prefix , local ] = curie . split ( ":" ) ;
532530 const namespace = this . prefixes . get ( prefix ) ;
533531 return namespace ? `${ namespace } ${ local } ` : curie ; // Return as-is if prefix not found
534532 } else {
@@ -542,13 +540,14 @@ function extractAllSubjectsAndTypes(query: string): Map<string, Set<string>> {
542540 const subjectTypeMap = new Map < string , Set < string > > ( ) ;
543541 // Remove comments and string literals, and prefixes to avoid false matches
544542 const cleanQuery = query
545- . replace ( / ^ # .* $ / gm, '' )
543+ . replace ( / ^ # .* $ / gm, "" )
546544 . replace ( / ' (?: [ ^ ' \\ ] | \\ .) * ' | " (?: [ ^ " \\ ] | \\ .) * " / g, '""' )
547- . replace ( / ^ P R E F I X \s + .* $ / gmi , '' ) // Remove PREFIX/prefix lines;
548- . replace ( / ; \s * \n / g, '; ' ) // Also put all triple patterns on a single line
549- . replace ( / ; \s * $ / g, '; ' ) ;
545+ . replace ( / ^ P R E F I X \s + .* $ / gim , "" ) // Remove PREFIX/prefix lines;
546+ . replace ( / ; \s * \n / g, "; " ) // Also put all triple patterns on a single line
547+ . replace ( / ; \s * $ / g, "; " ) ;
550548 // console.log(cleanQuery)
551- const typePattern = / \s * ( \? \w + | < [ ^ > ] + > ) .* ?\s + (?: a | r d f : t y p e | < h t t p : \/ \/ w w w \. w 3 \. o r g \/ 1 9 9 9 \/ 0 2 \/ 2 2 - r d f - s y n t a x - n s # t y p e > ) \s + ( [ ^ \s . ] + ) \s * (?: ; | \. ) / g;
549+ const typePattern =
550+ / \s * ( \? \w + | < [ ^ > ] + > ) .* ?\s + (?: a | r d f : t y p e | < h t t p : \/ \/ w w w \. w 3 \. o r g \/ 1 9 9 9 \/ 0 2 \/ 2 2 - r d f - s y n t a x - n s # t y p e > ) \s + ( [ ^ \s . ] + ) \s * (?: ; | \. ) / g;
552551
553552 let match ;
554553 while ( ( match = typePattern . exec ( cleanQuery ) ) !== null ) {
@@ -564,23 +563,22 @@ function extractAllSubjectsAndTypes(query: string): Map<string, Set<string>> {
564563}
565564
566565function getSubjectForCursorPosition ( query : string , lineNumber : number , charNumber : number ) : string | null {
567- const lines = query . split ( '\n' ) ;
566+ const lines = query . split ( "\n" ) ;
568567 const currentLine = lines [ lineNumber ] ;
569568 // Extract the part of the line up to the cursor position
570569 const partOfLine = currentLine . slice ( 0 , charNumber ) ;
571- const partialQuery = lines . slice ( 0 , lineNumber ) . join ( '\n' ) + '\n' + partOfLine ;
570+ const partialQuery = lines . slice ( 0 , lineNumber ) . join ( "\n" ) + "\n" + partOfLine ;
572571 // Put all triple patterns on a single line
573- const cleanQuery = partialQuery . replace ( / ; \s * \n / g, '; ' ) . replace ( / ; \s * $ / g, '; ' ) ;
574- const partialLines = cleanQuery . split ( '\n' ) ;
572+ const cleanQuery = partialQuery . replace ( / ; \s * \n / g, "; " ) . replace ( / ; \s * $ / g, "; " ) ;
573+ const partialLines = cleanQuery . split ( "\n" ) ;
575574 const lastLine = partialLines [ partialLines . length - 1 ] ;
576575 const subjectMatch = lastLine . match ( / ( [ ? \w ] + | [ < \w ] + > ) \s + / ) ;
577- if ( subjectMatch ) {
578- return subjectMatch [ 1 ] ;
579- }
576+ if ( subjectMatch ) {
577+ return subjectMatch [ 1 ] ;
578+ }
580579 return null ;
581580}
582581
583-
584582customElements . define ( "sparql-editor" , SparqlEditor ) ;
585583
586584// https://github.com/joachimvh/SPARQLAlgebra.js
0 commit comments