wiki:queryResource

Querying TNTBase

Method

  • URL: /query/{query}
    • Method: GET
    • Query parameters:
      • numResults - max number of results to be returned (default: -1)
      • startFrom - starting from N-th result (default: 1)
      • rev - revision of documents to be queried
      • cache (true or false) - tell TNTBase that a user wants to cache XQuery results. It might be useful when XQuery takes a while to be executed. If this option is set to true (default: false) then in the returned result set there is a unique id specified, which you can use to retrieve XQuery cached results. See section Caching XQuery results? for more details.
      • omdocNs (true or false): whether we want to bind OMDoc namespace to the empty prefix (default: true)
      • ns - a list of namespaces with prefixes that we want to use when querying. The format is the following: prefix:namespace. Note than prefixes can not be repeated
    • Returns: text/xml
    • Description: returns wrapped XML results after query execution. One can query the whole collection of TNTBase (providing collection(), the particular document in the database (providing doc(doc_path) in front of query) and collection of particular documents (providing collection(path_with_regexp_symbols)). Note that only relatively short queries can be used in this method due to the URL length constraints. Also it worth mentioning that if you provide rev parameter which differs from -1, then only those documents will be queries which were cached for the specified revision. Thus you can control which files will be affected by XQuery

Example

  • URL:  http://localhost:8080/TNTBase/restful/query/doc(/omstd/relation1.omdoc)/omdoc/metadata
  • Method: GET
  • Result: Root metadata elements in the /omstd/relation1.omdoc document. Again they are presented in the XML result set.
    <tnt:results xmlns:tnt="http://tntbase.mathweb.org/ns" startFrom="1" numResults="1">
      <tnt:result>
        <metadata xmlns="http://www.mathweb.org/omdoc">
          <dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">The OpenMath Content Dictionary relation1.ocd  in OMDoc form</dc:title>
          <dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/" role="trl">Michael Kohlhase</dc:creator>
          <dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/" role="ant">The OpenMath Society</dc:creator>
          //more metadate goes here
        </metadata>
      </tnt:result>
    </tnt:results>
    

Method

  • URL: /query
    • Method: POST
    • Accepts: the XQuery query in the body
    • Query parameters:
      • numResults - max number of results to be returned (default: -1)
      • startFrom - starting from N-th result (default: 1)
      • rev - revision of documents to be queried
      • cache - whether we want to cache XQuery results. See above for a better explanation.
      • omdocNs (true or false): whether we want to bind OMDoc namespace to the empty prefix (default: true)
      • ns - a list of namespaces with prefixes that we want to use when querying. The format is the following: prefix:namespace. Note than prefixes can not be repeated
    • Returns: text/xml
    • Description: the same as the above method, but contains an XQuery expression in the body of a request, but not as a part of url

Example

  • URL:  http://localhost:8080/TNTBase/restful/query?numResults=1&ns=it_should_be_default_for_all_XML_documents:http://www.mathweb.org/omdoc
  • Request body:
      collection(//om*td/*)/it_should_be_default_for_all_XML_documents:omdoc/it_should_be_default_for_all_XML_documents:theory/it_should_be_default_for_all_XML_documents:symbol
    
  • Method: POST
  • Result: Returns the first symbol in all documents in all folders which have the begging of om and the ending of td. Note that namespaces' declaration are important in some documents. Note that we use the new namespace prefix only for querying.
    <tnt:results xmlns:tnt="http://tntbase.mathweb.org/ns" startFrom="1" numResults="1">
      <tnt:result>
        <symbol xmlns="http://www.mathweb.org/omdoc" name="eq" xml:id="eq">
          <metadata>
            <dc:description xmlns:dc="http://purl.org/dc/elements/1.1/">
              This symbol represents the binary equality function.
            </dc:description>
            <dc:subject xmlns:dc="http://purl.org/dc/elements   /1.1/">eq</dc:subject>
          </metadata>
          <type system="sts.omdoc#sts">
            <OMOBJ xmlns="http://www.openmath.org/OpenMath">
              <OMA>
    	    <OMS name="mapsto" cd="sts" />
    	    <OMS name="Object" cd="sts" />
    	    <OMS name="Object" cd="sts" />
    	    <OMS cd="setname2" name="Boolean" />
              </OMA>
            </OMOBJ>
          </type>
        </symbol>
      </tnt:result>
    </tnt:results>