SPARQL support is an addon of the CodeMirror to support editing SPARQL queries in a textarea.
Auto-Completion : "Ctrl+Space" or "Tab", Submit : "Ctrl+Enter"

Auto-Completion

Complement indents, variable names and prefixes with the "Ctrl+Space" or "Tab" key.

e.g.)	
?h|             -->   ?hoge|
r|              -->   rdf:|                                                       *lower case
F|              -->   FILTER (|)                                                  *upper case
PREFIX obo:|    -->   PREFIX obo: <http://purl.obolibrary.org/obo/>|              *1
<id>|           -->   <http://identifiers.org/>|                                  *2

*1 Prefix URIs will be taken from prefix.cc.
*2 Private abridgement of URIs. Default has only this example. User is able to add in the comment line.(format : # id:<http://identifiers.org/>)

Copy code and prefixes in other query.

e.g.) copy the 2nd query prefixes
PREFIX #2|    -->   PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>     *3
                    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
                    PREFIX dct: <http://purl.org/dc/terms/>
		    |
e.g.) copy the 1st query
COPY #1|      -->   omit

*3 run in the 1st line of textarea.

Other completion

###|  ->   ### endpoint|                             * 1st line only
Def|  ->   DEFINE sql:select-option "order"|         * (for Virtuoso)

set endpoint

### endpoint http://example.org/                       * 1st line only

Tabbed Interface

Available multiple queries management by the '+' and the '-' button in the upper right corner. Queries are retained when the browser is restarted.
"Ctrl+Shift" : move to neighbor tab ("Ctrl+Alt+Shift", "Ctrl+[1-9]")
"Ctrl+[+/-]" : add/remove tab(w/o Shift)

innerMode

Change the mode to click the 'i' button in the upper right corner.
Output results in new element in the current window.
Complement variable names start with '$'.(by the tab key)

e.g.)
$p|             -->   rdf:type
                -->   rdfs:subClassOf
                -->   piero:inRpairInSideA
                -->   piero:inRpairInSideB

Command

Submit with "Ctrl+Enter"

- SPANG like shortcut.

e.g.) 
# spang -S tax:9606 -L 100;|    -->   # spang -S tax:9606 -L 100;                 *4, 5
                                      SELECT *
                                      WHERE {
				        tax:9606 ?p ?o .
				      }
		                      LIMIT 100|

*4 supported options: -S (subject), -P (predicate), -O (object), -L (limit), -N (count), -G (graph list), -F (from a graph)
*5 rewrite under the command line.

- Font size

# font-size:20px;

- Clear all queries

# clear_sparql_queries;                                 * 1st line only

Beta

Multi-line comments for debug
- skip through from '=begin' to '=end' (available '=b' and '=e', support in the innerMode only)

=begin
     multi
     line
     comments
=end
   
=b multi-line
   comments =e

Predicate search
- show predicates and sample of objects: "?subject ??p" (reverse search: "?subject ^??p", support in the innerMode only)

### endpoint http://dbpedia.org/sparql
PREFIX dbpedia: <http://dbpedia.org/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT *
WHERE {
  dbpedia:Tokyo dbo:isPartOf ?parent .
  ?parent ??p
}

----- results bindings -----
??p	        sample
dbo:utcOffset	"+9"
owl:sameAs	http://rdf.freebase.com/ns/m.0g3bw
dbo:timeZone	dbpedia:Japan_Standard_Time
dbo:length	1.3e+06
rdfs:label	"Honshu"
dbo:country	dbpedia:Japan
...

Demo or Simple page version 0.7.8


or UserScript

sparqlSupport.user.js
Set target URLs in "// @include" line
(or DL modified js)

require: userscript manager

or Embed

require: CodeMirror

	root
	+---codemirror/
	|   +---lib/
 	|   |   +---codemirror.js
	|   |   +---codemirror.css
	|   |
   	|   +---mode/sparql/sparql.js # colors mod. & fixed indent
	|
	+---sparql-suppor.js # 
	
	base.css
      

e.g.

<html>
  <head>
    <script type="text/javascript" src="./js/codemirror/lib/codemirror.js"></script>
    <script type="text/javascript" src="./js/codemirror/mode/sparql/sparql.js"></script>
    <script type="text/javascript" src="./js/codemirror/addon/edit/matchbrackets.js"></script>
    <script type="text/javascript" src="./js/codemirror/addon/edit/closebrackets.js"></script>
    <link rel="stylesheet" type="text/css" href="./js/codemirror/lib/codemirror.css">
    <script type="text/javascript" src="./js/sparql-support.js"></script>
    <link rel="stylesheet" type="text/css" href="./css/base.css">
  </head>
  <body>
    <div>
      <form action="http://endpoint" method="get">
	<textarea id="query" cols="100" rows="15">
      </textarea>
      <input type="submit" value="Run Query" id="submit_button">
      </form>
    </div>
   <script type="text/javascript">
    var id = "query";
    var editor = CodeMirror.fromTextArea(document.getElementsByName(id), {
       mode: "application/sparql-query",
       matchBrackets: true,
       autoCloseBrackets: true,
       lineNumbers: true,
       sparqlSupportAutoComp: id,      // Auto completion
       sparqlSupportQueries: id,       // Tabbed interface
       sparqlSupportInnerMoed: id,     // Inner mode
       extraKeys: {"Tab": function(instance) { return false; },
                   "Ctrl-Space": function(instance) { return false; }}
     });
   </script>
  </body>
</html>
      

-

DBCLS
moriya@dbcls.rois.ac.jp