示例#1
0
router.get("/document/:id",function(req,res){
	//searches for document containing that id
	client.execute(basexQuery + "(//TEI[@xml:id= '" + req.params.id + "' ])",
		function (error, result) {
			if(error){ console.error(error)}
			else{
				var $ = cheerio.load(result.result, {
					xmlMode: true
				});
				var title = $("title").first().text();
				var author = $("author").first().text();
				var body = $("body").first().html();
				var templateData = { 
					name: title,
					author: author,
					body: body,
					href: "/download/" + req.params.id
				};
				res.render('document', templateData);
			}
		}
	);
});
示例#2
0
router.get('/browse', function(req, res) {
  //console.log(req.query.document);
  client.execute("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0'; for $n in //teiHeader \n return (doc(base-uri($n))//titleStmt, base-uri($n))",
  function(error, result){
    var content;
    if(error){
      console.log(error);
      content = "There was an error accessing the database: " + error;
      res.render('browse', { title: title, content:content });
    }
    else {
      var content = "";
      if(result.result){
        var resultArray = result.result.split(".xml");
        var URIlist = "";
        content = "<p>Viewing all letters: </p> <div id='resultsTable'><form action='document'>";
          for(i = 0 ; i < resultArray.length - 1; i++ ){
            var currentResult = resultArray[i].split("</titleStmt>");
            if(URIlist.indexOf(currentResult[1]) == -1){
              URIlist +=currentResult[1];
              var titleStmtArray = currentResult[0].split("<author>");
              content += "<div class= 'result'><button name='documentURI' value='" + currentResult[1] + ".xml'>" + titleStmtArray[0] + "Written by <author>" +titleStmtArray[1] + "</button></div>";
            }
          }
        content+= "</form></div>";
      }
      else{
        content = "No documents were found :("
      }
      //split on author tag?
      //throw extra formating tags in and table
      res.render('search', { title: title, content: content });
  }
}
  );

});
示例#3
0
router.get('/download', function(req, res) {
    var queries = req.query;
    var fullpath  = queries.path.split('/');
    var filename = fullpath[fullpath.length - 1];
    client.execute("XQUERY doc ('Colenso/" + queries.path + "')",
        function(error, result) {
            if(error){
                console.error(error);
            } else {
                var doc = result.result;

                //response.writeHead(statusCode[, statusMessage][, headers])#
                //Sends a response header to the request. The status code is a 3-digit HTTP status code,
                //like 404. The last argument, headers, are the response headers. Optionally one can give a human-readable
                //statusMessage as the second argument.

                res.writeHead(200, {
                    'Content-Disposition': 'attachment; filename=' + filename
                });
                res.write(doc);
                res.end();            }
        }
    )
});
示例#4
0
router.get("/xQuerySearch", function(req, res){
	var url = req.protocol  + '://' + req.get('host') + req.originalUrl;
	var search = req.query.searchString;
	if(search === undefined){
		res.render('xQuerySearch', {results: [], searchString: '', numResults: ''});
	} else {
		client.execute((tei + "for $n in " + search + " return db:path($n)"),
			function (error, result) {
				if (error) {
					res.render('xQuerySearch', {
						results: '', searchString: 'Search results for ' + search + '   Error: ' + error
					});
					console.error(error);
				} else {
					var content = result.result.split('\n');
					if(content[0] === "") content = [];
					res.render('xQuerySearch', {
						results: content, searchString: 'Search results for ' + search,
						numResults: content.length + ' results found', url:url
					});
				}
			});
	}
});
router.get("/searchStringResult",function(req,res){
  var query = req.query.query;
  var isRaw = req.query.raw;
  console.log("Query is: " + query);
  //var searchQuery = ("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1,0';" +
      //"for $v in .//TEI[. contains text"+query+"]return db:path($v)");
  //var searchQuery = ("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0';" +
    //"for $n in (collection('Colenso'))");
  var searchQuery = ("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0';" + "for $v in .//TEI[. contains text "+query+"] return db:path($v)");
  console.log("Search Query is: " + searchQuery);
  client.execute((searchQuery),
  function (error, result) {
    if(error){
	     console.error(error);
	  }
	  else {
      var fileList = result.result.split('\n');
      var length = fileList.length;
      console.log(fileList);
      console.log(length);
      res.render('searchStringResult', { title: 'Colenso Project', files: fileList, searchString: query, numResults: length, raw: isRaw  });
	 }
	});
});
exports.browseDatabase = function(quer, callb) {
    client.execute("LIST Colenso",
        function(error, result) {
            if (error) {} else {

                index = 0;
                path = [];
                pathtemp = "";
                while (result.result.length > index) {
                    if (result.result.charAt(index) == " ") {
                        if (pathtemp.charAt(pathtemp.length - 1) == 'l' && pathtemp.charAt(pathtemp.length - 2) == 'm' && pathtemp.charAt(pathtemp.length - 3) == 'x' && pathtemp.charAt(pathtemp.length - 4) == '.') {
                            path.push(pathtemp);
                        }
                        pathtemp = "";
                    } else {
                        pathtemp += result.result.charAt(index);
                    }
                    index++;
                }
                path[0] = path[0].replace(/(-{3,})/gm, "");
                for (i = 0; i < path.length; i++) {

                    path[i] = path[i].replace('.xml', '/');
                }

                page = "";
                page += "<table class=\"table-striped\">";
                for (i = 0; i < path.length; i++) {
                    //add href link
                    page += "<tr><td><a href=\"../results/" + path[i] + "\">" + path[i] + "</a></td></tr>";
                }
                callb(undefined, page);
            }
        }
    )
};
示例#7
0
var multer = require('multer');
var upload = multer({dest: './uploads'});

//for renaming files
var fs = require('fs');

//zip file 
var zip = new require('node-zip')();

var express = require('express');
var router = express.Router();

var cheerio = require('cheerio');

var basex = require('basex');
var client = new basex.Session("127.0.0.1", 1984, "admin", "admin");

var nestCount = 0;
var searchText = [];
var searchHistory = [];
client.execute("open Colenso");

//client.execute("xquery //movie[position() lt 10]",console.log);
router.get("/",function(req,res,next){
/**
client.execute("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0'; "+
			"for $t in (//title) where $t= '24 August 1863: Hooker to Haast.' return db:path($t)",
			//function(err,res) { if(!err) console.log(res.result)},
**/

//client.execute("XQUERY doc('Colenso/McLean/private_letters/PrLMcL-0024.xml')",
示例#8
0
var express = require('express');
var multer = require('multer');
var router = express.Router();

var uploading = multer();
router.use(uploading.single('file'));

var cheerio = require('cheerio');
var basex = require('basex');
var client = new basex.Session("127.0.0.1", 1984, "admin", "admin");

client.execute("OPEN Colenso");

//Edited doc with explanations from lecture 3 notes.
// The initial database check, confirms opening of Database.
// Roman tutorial add below, from sheet.

client.execute("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0'; " +
    "//name[@type = 'place' and position() = 1 and . = 'Manawarakau']",
    function(err,res) { if(!err) console.log(res.result)} );

router.get("/",function(req,res) {
    res.render('index', {title: 'Colenso Database'});
});



// Returns all files for rendering to the browse tab.
router.get("/browse",function(req,res) {

    var queries = req.query;
示例#9
0
		query.execute(function (err, result) {
				callback(result);
				session.close();
			
		});		
示例#10
0
	this.validateXML = function(xmlToValidate, callback){
		

		var session = new basex.Session("localhost", 1984, "admin", "admin");
		var validateXMLQuery = 'let $doc := ' + xmlToValidate +
							" let $schema := 'http://www.tei-c.org/release/xml/tei/custom/schema/xsd/tei_all.xsd'" +
							' return validate:xsd($doc, $schema)';
							
		var query = session.query(validateXMLQuery);
		console.log(validateXMLQuery);
		query.execute(function (err, result) {
				callback(result);
				session.close();
			
		});		
		
			/*
		
		var tmpobj = tmp.fileSync();
		console.log("File: ", tmpobj.name);
		console.log("Filedescriptor: ", tmpobj.fd);
		
		var session = new basex.Session("localhost", 1984, "admin", "admin");
		var validateXMLQuery = "XQUERY validate:xsd('" + tmpobj.name+ "', 'http://www.tei-c.org/release/xml/tei/custom/schema/xsd/tei_all.xsd')";
		//var query = session.query(validateXMLQuery);	
		// If we don't need the file anymore we could manually call the removeCallback 
		// But that is not necessary if we didn't pass the keep option because the library 
		// will clean after itself. 
		console.log(validateXMLQuery);
		session.execute("XQUERY validate:xsd('" + tmpobj.name+ "', 'http://www.tei-c.org/release/xml/tei/custom/schema/xsd/tei_all.xsd')", function (err, result) {				
				console.log(err);
				console.log(result);
				callback(result);
				session.close();
				tmpobj.removeCallback();
				
			});
		
		tmp.file(function _tempFileCreated(err, path, fd, cleanupCallback) {
			  if (err) throw err;
			  var session = new basex.Session("localhost", 1984, "admin", "admin");
			  console.log("File: ", path);
			  console.log("Filedescriptor: ", fd);
			  var validateXMLQuery = "XQUERY validate:xsd('" + path+ "', 'http://www.tei-c.org/release/xml/tei/custom/schema/xsd/tei_all.xsd')";
			  var query = session.query(validateXMLQuery);
			console.log('VALIDATING XML QUERY \n****************************'  + validateXMLQuery);
			query.execute(function (err, result) {				
				console.log(err);
				console.log(result);
				callback(result);
				session.close();
				
			});
			  // If we don't need the file anymore we could manually call the cleanupCallback 
			  // But that is not necessary if we didn't pass the keep option because the library 
			  // will clean after itself. 
			  console.log("closing file");
		});


		var schemaPath ="resources/tei_bare.xsd"; 
		fs.readFile(schemaPath, 'utf-8', function(err, schema){
			if (err){
				console.log("error in readfile");
				console.log(err);
				callback({ok:false});
			}
			var session = new basex.Session("localhost", 1984, "admin", "admin");
			var validateXMLQuery = 'let $doc := ' + xmlToValidate +
								" let $schema := '"  + schema +
								"' return validate:xsd($doc, $schema)";
								
			var query = session.query(validateXMLQuery);
			console.log('VALIDATING XML QUERY \n****************************'  + validateXMLQuery);
			query.execute(function (err, result) {				
				callback(result);
				session.close();
			});
			});
			
		});
		var schemaPath ="resources/tei_all.xsd";
		xsd.parseFile(schemaPath, function(err, schema){
			schema.validate(xmlToValidate, function(err, validationErrors){
				if (err){console.log(err);}
				else {
					console.log(validationErrors);
					if(!validationErrors){
						callback({ok:true});					
					}else{
					callback({ok:false});
					}
				}			
			
			});
		});
		*/
	},
示例#11
0
router.get('/search', function(req, res, next) {

    searchmap

    //router.use(bodyParser.text());
    client = new basex.Session("127.0.0.1", 1984, "admin", "admin");
    var url_parts = url.parse(req.url, true)
    var query = url_parts.query;


    //if query type is standard do a normal style database search
    if(query.query==="standard"){

        //a little bit of map logic to keep track of searches - complicated because js is complicated
        //add to map, search as key, value as number
            if(searchmap[query.search]===undefined){
                searchmap[query.search] = 1;
            } else {
                searchmap[query.search]=searchmap[query.search]+1;
            }
            //now we determine whats in our array of search terms
            var newObject =  JSON.parse(JSON.stringify(searchmap));
            var highcount=0;
            var highstring;
            var i=0;

            var totalsearches=0;
            for (var item in searchmap){
                totalsearches+=searchmap[item];
            }


            for(; i<5; i++ ) {
                if(i===totalsearches){ break;}

                for (var item in newObject) {
                    if (newObject[item] > highcount) {
                        highcount = newObject[item];
                        highstring = item;
                    }
                }

                stringarray[i] = highstring;
                newObject[highstring]=0;
                highcount=0;

            }

        //figure out proper query for string with multiple words
        var arrayOfWords = query.search.split(" ");

        //check for logical operators
        //if(arrayOfWords.indexOf("&")>-1){
        //    console.log("ampersand detected");
        //}

        var altquery = '';
        client.execute('open Colenso_TEIs');
        //loop through to construct string query
        for(var i = 0; i<arrayOfWords.length; i++){


            if(arrayOfWords[i]==="&") {
                altquery = altquery + ' /descendant-or-self::*[text() contains text "' + arrayOfWords[i] + '\"] ftand ';
            }
            else if (arrayOfWords[i]==="!"){
                    altquery = altquery + ' /descendant-or-self::*[text() contains text "' + arrayOfWords[i] + '\"] ftnot ';
                }
             else {

                altquery = altquery + ' /descendant-or-self::*[text() contains text "' + arrayOfWords[i] + '\"] | ';

            }


        }
        //s
        altquery = altquery.substring(0,altquery.length-3);

        var myquery = ' /descendant-or-self::*[text() contains text "' + query.search + '\"]';


        var result = client.query(altquery);

            result.execute( function(error, result){
                if(error) {
                    console.error(error);
                } else{
                    //result.result=result.result.replace(/<\/p>/g,"\n");
                    res.render('searchpage', { xmlstuff: result.result, title: 'Colenso Project', queryType: query.query, popular1:stringarray[0], popular2:stringarray[1], popular3:stringarray[2], popular4:stringarray[3], popular5:stringarray[4]});
                }
            });
            client.execute('exit', function () {
                console.log('session exited');
            });


        //otherwise run a specific jquery search
    } else if (query.query==='jquery') {

        client.execute('open Colenso_TEIs');

        var myquery = "XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0'; " ;

        myquery = myquery + query.search;
        console.log(myquery);

        //var result = client.query(myquery);
        var success;

        client.execute( myquery, function(error, result){
            if(error) {
                console.error(error);
                success=false;
            } else{
                success=true;
                //result.result=result.result.replace(/<\/p>/g,"\n");
                res.render('searchpage', { xmlstuff: result.result, title: 'Colenso Project', queryType: query.query, popular1:stringarray[0], popular2:stringarray[1], popular3:stringarray[2], popular4:stringarray[3], popular5:stringarray[4]});
            }



        });

        if(!success){
            console.log("trying alt query");
            var alternativequery = "XQUERY declare namespace tei= 'http://www.tei-c.org/ns/1.0'; " ;
            alternativequery= alternativequery+query.search;
            client.execute(alternativequery,function(error,result){
                if(error){
                    console.log("total error")
                }
                else {
                    res.render('searchpage', { xmlstuff: result.result, title: 'Colenso Project', queryType: query.query, popular1:stringarray[0], popular2:stringarray[1], popular3:stringarray[2], popular4:stringarray[3], popular5:stringarray[4]});
                }

            });
        }
        client.execute('exit', function () {
            console.log('session exited');
        });

    }

});
示例#12
0
router.get ( '*/browse', function ( req, res) {
    var original_dir = req.originalUrl.replace('/','').replace('/browse', '').split('/');
    var depth = original_dir.length;
    var query = tei +
        "for $n in (//TEI)\n" +
        "return concat('<result><path>', db:path($n), '</path>\n <title>', $n//title, '</title>\n <size>', string-length($n), '</size></result>\n')";
    client.execute(query, function (error, result) {
        if ( error ) {
            console.error ( error );
        } else {
            var results = [];
            var count = 0;
            var subdirectories = [];
            var isPush;
            if (depth > 1) {
                $ = cheerio.load(result.result, {xmlMode: true});
                $('result').each(function (i, elem) {
                    isPush = true;
                    var path = $(elem).find('path').first().text();
                    var path_directories = path.split('/');
                    var original_p = '';
                    var path_d = '';
                    for (var i = 0; i < depth-1; i++){
                        original_p = original_p + original_dir[i+1] + '/';
                    }
                    for (var i = 0; i < depth-1; i++){
                        path_d = path_d + path_directories[i] + '/';
                    }
                    if (original_p == path_d) {
                        for (var i = 0; i < subdirectories.length; i++) {
                            if (subdirectories[i] == path_d + path_directories[depth - 1]) {
                                isPush = false;
                            }
                        }
                        if (isPush) {
                            subdirectories.push(path_d + path_directories[depth - 1]);
                            count++;
                        }
                        results[i] = {
                            path: path,
                            title: $(elem).find('title').first().text(),
                            size: $(elem).find('size').first().text()
                        }
                    }
                });
            } else {
                $ = cheerio.load(result.result, {xmlMode: true});
                $('result').each(function (i, elem) {
                    isPush = true;
                    var path = $(elem).find('path').first().text();
                    var path_directories = path.split('/');
                    for (var i = 0; i < subdirectories.length; i++) {
                        if (subdirectories[i] == path_directories[0]) {
                            isPush = false;
                        }
                    }
                    if (isPush) {
                        subdirectories.push(path_directories[0]);
                        count++;
                    }
                    results[i] = {
                        path: path,
                        title: $(elem).find('title').first().text(),
                        size: $(elem).find('size').first().text()
                    }
                });
            }
            res.render('browse', {title: 'Browse', results: results, count: count, subdirectories: subdirectories, depth: depth, original_dir: original_dir});
        }
    } );
} );
示例#13
0
var express = require('express');
var router = express.Router();
var basex = require('basex');
var client = new basex.Session("127.0.0.1", 1984, "admin", "admin");
var reWORD = /\s*([^\s\(\)]+)\s*/g;
var reAND = /\}?\'AND\'\s?\{?/g;
var reOR = /\}?\'OR\'\s?\{?/g;
var reNOT = /\{?\s*\'NOT\'\s?\{?/g;
var reOPENBRACE = /\{?\(/g;
var reCLOSEBRACE = /\)\}?/g;
var authorList = ["Broughton", "Colenso", "Cotton", "Elizabeth_Colenso", "Haast", "Hadfield", "Hector", "Hogg", "Holmes", "Hooker", "Kate_Hadfield",
"McLean", "Tamihana_Te_Rauparaha", "unknown_author"];
var authors = [];
client.execute("OPEN Colenso");

client.execute("XQUERY declare namespace tei='http://www.tei-c.org/ns/1.0'; " + "count(collection('Colenso/'))",
	function(err,res) {
		if(!err) numColensoDB = res.result
	})

for(var i = 0; i < authorList.length; i++)
{
	author = authorList[i];
	client.execute("XQUERY declare namespace tei='http://www.tei-c.org/ns/1.0'; " + "count(collection('Colenso/" + author + "'))",
		function(err,res) {
			if(!err){
				authors.push([authorList[authors.length],res.result]);
			}
		})
}
示例#14
0
router.get("/stringSearch", function(req, res){
	var url = req.protocol  + '://' + req.get('host') + req.originalUrl;
	var search = req.query.searchString;

	function convertLogicStatementsToXQuery(str) {
		var arr = str.split(' ');
		while (arr.indexOf('and') != -1)
			if (arr.indexOf('and') != -1) arr[arr.indexOf('and')] = 'ftand';
		while (arr.indexOf('or') != -1)
			if (arr.indexOf('or') != -1) arr[arr.indexOf('or')] = 'ftor';
		while (arr.indexOf('not') != -1)
			if (arr.indexOf('not') != -1) arr[arr.indexOf('not')] = 'ftnot';

		return arr;
	}
	function formatSearchInputToXQuery(arr){
		var q = "'";
		for(var i = 0; i < arr.length; i++){
			if(arr[i] != 'ftand' && arr[i] != 'ftor' && arr[i] != 'ftnot') {
				q +=  arr[i] + " ";
			} else {
				q += "'" + arr[i] + "'";
			}
		}
		q += "'";

		//remove unwanted quotes for not
		for(var j = 0; j < q.length -1; j++){
			var x, y, z = ' ';
			if(q.substring(j, j+2) === "''"){
				x = q.substring(0,j);
				y = q.substring(j+2, q.length);
				z = x + " " + y;
				console.log(z);
				q = z;
			}
		}

		console.log(q);
		return q;
	}

	if(search === undefined){
		res.render('stringSearch', {results: [], searchString: '', numResults: ''});
	} else {
		//var query = search;
		var query = formatSearchInputToXQuery(convertLogicStatementsToXQuery(search));
		//query = "'william 'ftnot' colenso'";

		client.execute((tei + "for $n in .//TEI[ . contains text " + query + "]" + " return db:path($n)"),
			function (error, result) {
				if (error) {
					console.error(error);
				} else {
					var content = result.result.split('\n');
					if(content[0] === "") content = [];
					res.render('stringSearch', {
						results: content, searchString: 'Search results for ' + search,
						numResults: content.length + ' results found', url: url
					});
				}
			});
	}
});
示例#15
0
/* Gets the correct folder view or the given address */
function renderFolders(req, res, dirPath, dirDepth) {

  client.execute("LIST Colenso "+dirPath, function(error, result) {
      
      if(error) {
        console.error(error);
      } else {

        // PART 1/2 -  SEE WHERE YOU ARE
        console.log("\n");
        var fileArray = result.result.split("\n");
        var folderMap = new Map();
        var folderArray = [];
        var folderStr = "";

        // Add folders to Map, Array and Str
        for (var i = 2; i < fileArray.length - 3; i++) {

          var line = fileArray[i];
          var name = "";
          var isFile = false;
          var slash_index = line.indexOf("/");
          var space_index = line.indexOf(" ");

          for (var depth = 0; depth < dirDepth; depth++) {
            slash_index = line.indexOf("/", (slash_index+1));
          }

          if (space_index < slash_index) {
            isFile = true;
            name = "/" + line.slice(0, space_index);
            //console.log("- FILE!, File?");
          } else {
            name = "/" + line.slice(0, slash_index);
            //console.log("- FOLDER: "+slash_index+", "+space_index);
          }


          if (!folderMap.has(name)) {
            // Insert into Map
            if (isFile) {
              folderMap.set(name, 'file');
            } else {
              folderMap.set(name, 1);
            }
            folderArray.push(name);
          } else {
            // Increment Count
            folderMap.set(name, folderMap.get(name) + 1);
          }
        }
      }

      // Create folderStr
      for (var folder of folderMap.keys()) {
        var start = "/browse";
        if (folderMap.get(folder) === 'file') {
          start = "/view";
        }

        var tag = '<li class=list-group-item><span class="badge">{3}</span>\n  '+
                    '<a href="{0}{1}">'+
                      '{2}'+
                    '</a>\n'+
                  '</li>\n';

        tag = tag.format(start,
                         folder, 
                         folder.slice(1).replace(new RegExp("_", "g"), " "),
                         folderMap.get(folder));

        folderStr = folderStr + tag;
        console.log("Insert in Map  :   "+folder);
      }



      // PART 2/2 - FIGURE OUT WHERE YOU NEED TO GO
      console.log("\nPATH: "+req.path);
      console.log("DIRPATH: "+dirPath+"\n");
      var isStart = false;
      var isEqual = false;
      var dirName = "";
      var i = 0;
      
      while (!isEqual && i < folderArray.length) {
        
        if ((req.path !== "/") && req.path.startsWith(folderArray[i])) {
          isStart = true;
          dirName = folderArray[i];

          if (req.path === dirName) {
            isEqual = true;
          }
        }
        console.log(folderArray[i]+" : "+req.path);
        console.log("    start: "+isStart+"\n    equal: "+isEqual);
        i++;
      }


      if (dirPath === req.path) {
        // YOU ARE WHERE YOU'RE MENT TO BE! folderStr is Correct!!!
        renderPage(res, res, folderStr);
        console.log("\nRENDERED!!! SUCC!!!\n");

      } else if (isEqual) {
          renderFolders(req, res, dirName, dirDepth+1);

      } else if (isStart) {
        renderFolders(req, res, dirName, dirDepth+1);
          
      } else {
          console.log("NOT FOUND!!");
      }
    }
  );
}
示例#16
0
router.get('/', function(req, res, next) {
    var searchString = req.query.text;
    var count = req.query.count;
    var countString = "";
    if(count == undefined || count == ""){
        count = 1;
    }
    count = parseInt(count)
    countString = count.toString() + " to " + (count + 19).toString();
    var xPath = req.query.xPath;
    if(xPath == undefined || xPath == ""){
        xPath = "";
    }else if(xPath[0] == "["){
        xPath = xPath;
    }else{
        xPath = "[" + xPath + "]";
    }
    var rootPath = "./Colenso/";
    client.execute(
        "XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0';" +
        " for $n in (//" + searchString + xPath + ")[position() =(" + countString+")]\n"+
        "return $n\n",

        function (error, result) {
            if(error){
                console.error(error);
                res.render('results',{
                    title: 'Colenso Project Search Results',
                    xPath: xPath,
                    searchString: searchString,
                    failed: 'true'
                })
            }
            else {
                var stuff = result.result;
                stuff = stuff.substring(1 + searchString.length,stuff.length);
                stuff = stuff.split("<" + searchString);
                for(var i = 0; i < stuff.length;i++){
                    stuff[i] = "<" + searchString + stuff[i];
                }
                client.execute(
                    "XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0';"+
                    "for $n in (//" + searchString + xPath + ")[position() = (" + countString+")]\n" +
                    "return db:path($n)",
                    function (error, result){
                        if(error){
                            console.error(error);
                            res.render('results',{
                                title: 'Colenso Project Search Tags',
                                xPath: xPath,
                                searchString: searchString,
                                failed: 'true'
                            });
                        }
                        else{
                            client.execute(
                                "XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0';"+
                                "for $n in (//" + searchString + xPath + ")\n" +
                                "return db:path($n)",
                                function (error, result){
                                    if(error){
                                        console.error(error);
                                    }else{
                                        var results = result.result;
                                        results = results.split('\n');
                                        resultAmount = results.length
                                        var docPaths = result.result;
                                        docPaths = docPaths.split("\n");
                                        res.render('results', {
                                            title: 'Colenso Project Search Tags',
                                            query: stuff,
                                            searchString: searchString,
                                            rootPath: rootPath,
                                            docPaths: docPaths,
                                            xPath: xPath,
                                            count: count,
                                            resultAmount:resultAmount
                                        });
                                    }
                                }
                            )
                        }
                    }
                )
            }
        }
    );
});
示例#17
0
 function (error, result) {
     if(error){
         console.error(error);
         res.render('results',{
             title: 'Colenso Project Search Results',
             xPath: xPath,
             searchString: searchString,
             failed: 'true'
         })
     }
     else {
         var stuff = result.result;
         stuff = stuff.substring(1 + searchString.length,stuff.length);
         stuff = stuff.split("<" + searchString);
         for(var i = 0; i < stuff.length;i++){
             stuff[i] = "<" + searchString + stuff[i];
         }
         client.execute(
             "XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0';"+
             "for $n in (//" + searchString + xPath + ")[position() = (" + countString+")]\n" +
             "return db:path($n)",
             function (error, result){
                 if(error){
                     console.error(error);
                     res.render('results',{
                         title: 'Colenso Project Search Tags',
                         xPath: xPath,
                         searchString: searchString,
                         failed: 'true'
                     });
                 }
                 else{
                     client.execute(
                         "XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0';"+
                         "for $n in (//" + searchString + xPath + ")\n" +
                         "return db:path($n)",
                         function (error, result){
                             if(error){
                                 console.error(error);
                             }else{
                                 var results = result.result;
                                 results = results.split('\n');
                                 resultAmount = results.length
                                 var docPaths = result.result;
                                 docPaths = docPaths.split("\n");
                                 res.render('results', {
                                     title: 'Colenso Project Search Tags',
                                     query: stuff,
                                     searchString: searchString,
                                     rootPath: rootPath,
                                     docPaths: docPaths,
                                     xPath: xPath,
                                     count: count,
                                     resultAmount:resultAmount
                                 });
                             }
                         }
                     )
                 }
             }
         )
     }
 }
示例#18
0
router.get('/search-text', function(req, res) {
if(req.query.searchString){
	//the following section handles logical operators and wildcard input
	var queryArray = req.query.searchString.split(" ");
	var queryString = "";
	var contains1 = "//TEI[. contains text '";
	var contains2 = "']";
	var wildcard = false;
	var firstElement = queryArray[0];
	var firstElementArray = firstElement.split("");
	var lastChar = firstElementArray[firstElementArray.length-1];
	var i = 0;
	if(firstElement==="NOT"){
		contains1 = "//*[not(. contains text '";
		contains2 = "')]";
		++i;
	}else if(lastChar==="*"){
		queryArray[0].replace("*", "");
		wildcard = true;
		contains1 = "//*[starts-with(., '";
		contains2 = "')]";
	}
	while(i < queryArray.length){
		queryString += queryArray[i];
		++i;
		if(i < queryArray.length){
			if(queryArray[i] ==="OR"){
				queryString += "' ftor '";
			}else if(queryArray[i] === "AND"){
				queryString += "' ftand '";
			}else{
				queryString = queryString + "' ftand '" + queryArray[i];
			}	
		}
		++i;
	}
}
if(wildcard){
	contains1 = "//TEI[.]";
	queryString = "";
	contains2 = "";
}
//the actual query begins here
client.execute(basexQuery + contains1 + queryString + contains2,
function (error, result) {
	var $;
	var list = [];
	if(error){ console.error(error)}
	else {
		if(req.query.searchString == undefined || req.query.searchString == null){
			res.render('search-text', { title: 'Colenso Database', results: " "});
		}else{
			//if the user has actually inputed something, and no error has occured:
			$  = cheerio.load(result.result, {
				xmlMode: true
			});
			$("TEI").each(function(i, elem){
				var title = $(elem).find("title").first().text();
				var id = $(elem).attr("xml:id");
				if(!id){
					return;
				}
				//Note: the href property is used to link to the document's "view" page
				list.push({title: title, href: "/document/" + id});
			});
			res.render('search-text', { visited: true, number: list.length, results: list});
		}
	}
		}
		);
});
示例#19
0
var express = require('express');
var router = express.Router();

var basex = require('basex');
var client = new basex.Session("127.0.0.1",1984,"admin","admin");

var fileName = "";
var tei =  "XQUERY declare default element namespace 'https://www.tei-c.org/ns/1.0';";

client.execute("OPEN Colenso");

/* GET home page. */
router.get("/",function(req,res){
	client.execute("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0';" +
		" (//name[@type='place'])[1] ",
		function (error, result) {
			if(error){ console.error(error);
		}
			else {
				console.log(req.query.searchString);
				res.render('index', { title: 'The Colenso Project'});

			}
		});
});

/*display all db items*/

client.execute("XQUERY db:list('Colenso')", function (error,result){

});
示例#20
0
router.get("/",function(req,res,next){
	console.log('execute0 : ' + client.state);
	resource = res;
	client.execute("xquery db:list('data')", listifyResult);	

});
示例#21
0
var express = require('express');
var basex = require('basex');
var fs = require('fs');
var router = express.Router();
var client = new basex.Session("127.0.0.1", 1984, "admin", "admin");


var tei = "XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0'; ";

client.execute("OPEN Colenso");
client.execute("DELETE file.xml");

function removeTagsFromString(string){
	var regex = /(<([^>]+)>)/ig
	,   body = string
	,   result = body.replace(regex, "|");
	return result;
}

function toArray(string){
	var arr = string.split('|');
	var resultArray = [];
	for(var i = 0; i < arr.length; i++){
		if(arr[i] !== '|'){
			resultArray[resultArray.length] = arr[i];
		}
	}
	return resultArray;
}

function resultsToString(arr){
示例#22
0
router.get("/nestedSearch",function(req,res,next){
	var title = req.query.title;
	var Bquery = req.query.Bquery;
	var text = req.query.text;
	var directory = process.env.PWD;
	var k = 0;
	var search = [];
	var nsearch = [];
	if(title){

		if(nestCount>0){

			client.execute("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0'; for $t in (//title) where matches($t,'" + title + "','i') return db:path($t)",   
			function(err,body) {  
				search = body.result.match(/[^\r\n]+/g);

				//removing all the results that were not in the seach result previously
				for(i=0;i<search.length;i++){

					for(j=0;j<searchText[nestCount-1].length;j++){

						if(search[i]==searchText[nestCount-1][j]){
							nsearch[k] = search[i];
							k++;
						}

					}

				}

				searchText[nestCount] = nsearch;

				if(k==0){
					searchText[nestCount] = undefined;
				}

				res.render('nsearch',{title: 'Nested Search Query: ' + nestCount, searchResult: searchText[nestCount], titleInput:title});
				nestCount++;

			});
		} else {
			client.execute("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0'; for $t in (//title) where matches($t,'" + title + "','i') return db:path($t)",   
				function(err,body) {  
					search = body.result.match(/[^\r\n]+/g);
					for(i=0;i<search.length;i++){
						searchHistory.push(search[i]);
					}
					searchText[nestCount] = search;
					res.render('nsearch',{title: 'Nested Search Query', searchResult: searchText[nestCount], titleInput:title});
					nestCount++;
				}
			);

		}
		
	} else if (Bquery){
		if(nestCount>0){

			client.execute("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0';" + Bquery + "return db:path($t)",   
			function(err,body) {  
				search = body.result.match(/[^\r\n]+/g);

				//removing all the results that were not in the seach result previously
				for(i=0;i<search.length;i++){

					for(j=0;j<searchText[nestCount-1].length;j++){

						if(search[i]==searchText[nestCount-1][j]){
							nsearch[k] = search[i];
							k++;
						}

					}

				}

				searchText[nestCount] = nsearch;

				if(k==0){
					searchText[nestCount] = undefined;
				}

				res.render('nsearch',{title: 'Nested Search Query: ' + nestCount, searchResult: searchText[nestCount]});
				nestCount++;

			});
		} else {
			client.execute("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0';" + Bquery + "return db:path($t)",   
				function(err,body) {  
					search = body.result.match(/[^\r\n]+/g);
					for(i=0;i<search.length;i++){
						searchHistory.push(search[i]);
					}
					searchText[nestCount] = search;
					res.render('nsearch',{title: 'Nested Search Query', searchResult: searchText[nestCount]});
					nestCount++;
				}
			);
		}
		// console.log(Bquery);
		// client.execute("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0';" + Bquery + "return db:path($t)",   
		// function(err,body) {  
		// 	search = body.result.match(/[^\r\n]+/g);
		// 	console.log("result"+search);
		// 	res.render('search',{title: 'Search Query', searchResult: search, queryInput:Bquery});
		// });
		
	} else if (text){
		if(nestCount>0){

			client.execute("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0'; for $t in *[.//text() contains text " + text + "]return db:path($t)",   
			function(err,body) {  
				search = body.result.match(/[^\r\n]+/g);

				//removing all the results that were not in the seach result previously
				for(i=0;i<search.length;i++){

					for(j=0;j<searchText[nestCount-1].length;j++){

						if(search[i]==searchText[nestCount-1][j]){
							nsearch[k] = search[i];
							k++;
						}

					}

				}

				searchText[nestCount] = nsearch;

				if(k==0){
					searchText[nestCount] = undefined;
				}

				res.render('nsearch',{title: 'Nested Search Query: ' + nestCount, searchResult: searchText[nestCount]});
				nestCount++;

			});
		} else {
			client.execute("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0'; for $t in *[.//text() contains text " + text + "]return db:path($t)",   
				function(err,body) {  
					search = body.result.match(/[^\r\n]+/g);
					for(i=0;i<search.length;i++){
						searchHistory.push(search[i]);
					}
					searchText[nestCount] = search;
					res.render('nsearch',{title: 'Nested Search Query', searchResult: searchText[nestCount]});
					nestCount++;
				}
			);
		}
		// console.log(text);
		// client.execute("XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0'; for $t in *[.//text() contains text " + text + "]return db:path($t)",
		// function(err,body) {  
		// 	search = body.result.match(/[^\r\n]+/g);
		// 	res.render('search',{title: 'Search Query', searchResult: search, textInput: text});
		// });
	} else {
		res.render('nsearch',{title: 'Nested Search'});
	}
  
});
示例#23
0
var express = require('express');
var router = express.Router();
var multer = require("multer");
var fs = require('fs');
var archiver = require('archiver');
var cheerio = require('cheerio');

/* Connect to basex and open database */
var basex = require('basex');
var client = new basex.Session("127.0.0.1", 1984, "admin", "admin");
client.execute('open Colenso');
var defaultDeclare = "declare default element namespace 'http://www.tei-c.org/ns/1.0'; "
var tei_schema =  'http://www.tei-c.org/release/xml/tei/custom/schema/xsd/tei_all.xsd';

/* Fields to deal with requests */
var mostRecentFiles = [];
var searchHistory = [];

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Colenso Project' });
});

/* GET browse all letters page. */
router.get('/browse', function(req, res, next) {
  var sel_link = req.query.select? req.query.select : '';
  var sel = sel_link === ''? 'All Authors' : sel_link.replace("/", "").replace("_", " ");
  client.execute("XQUERY for $x in file:list('Colenso') return <li>{$x}</li>",
  function(err, response){
    if(!err){
      var $ = cheerio.load(response.result);
示例#24
0
router.get('/search', function(req, res, next) {
  var query = req.query.query;
  var nested_num = req.query.num? req.query.num : 0;
  if(!query){
    res.render('search', {title: "Search", results: [], searched: false, num: nested_num});
    return;
  }
  var format = req.query.format;
  if(format === 'xquery'){
    var new_query = getXQueryQuery(query);
    client.execute(new_query.fixedQuery, function(err, data){
      if(!err){
        var $c = cheerio.load(data.result);
        var results_list = [];
        $c('li').each(function(i, elem){
          var link = $c(this).attr("path").trim().replace("\\", "/");
          results_list[i] = {
            title: $c(this).attr("title").trim(),
            author: fixText($c(this).attr("author").trim(), 50, false, false),
            date: fixText($c(this).attr("date").trim(), 20, true, false),
            context: fixText($c(this).text().trim(), 160, false, true),
            path: link,
            res: '',
            url: '/view?id=' + link
            }
        });
        $c(new_query.tag).each(function(i, elem){
          results_list[i].res = fixText($c(this).html(), 160, false, true);
        });
        mostRecentFiles = results_list;
        searchHistory.push({searchQuery: req.query.query, qtype: req.query.format, nested: nested_num, results: results_list});
        res.render('search', {title: "Search", results: results_list, query: req.query.query, searched: true, num: nested_num});
      } else {
        res.render('search', {title: "Search", results: [], searched: err, num: nested_num, query: req.query.query});
      }
    });
  }
  // deal with xpath and x queries
  else {
    if(nested_num > 0){
      query = getNestedQuery(query, format, nested_num);
    }
    // else not nested so treat normally
    else if(format === 'xpath'){
      query = getXPathQuery(query);
    } else {
      query = getStringQuery(query);
    }
    // execute xpath/string query
    client.execute(query, function(err, data){
      if(!err){
        var $c = cheerio.load(data.result);
        var results_list = [];
        $c('li').each(function(i, elem){
          var link = $c(this).attr("path").trim().replace("\\", "/");
          var query_res = '';
          if($c(this).attr("res")){
            query_res = fixText($c(this).attr("res").trim(), 160, false, true);
          }
          results_list[i] = {
            title: $c(this).attr("title").trim(),
            author: fixText($c(this).attr("author").trim(), 50, false, false),
            date: fixText($c(this).attr("date").trim(), 20, true, false),
            context: fixText($c(this).text().trim(), 160, false, true),
            path: link,
            res: query_res,
            url: '/view?id=' + link
            }
        });
        mostRecentFiles = results_list;
        searchHistory.push({searchQuery: req.query.query, qtype: req.query.format, nested: nested_num, results: results_list});
        res.render('search', {title: "Search", results: results_list, query: req.query.query, searched: true, num: nested_num});
      } else {
        res.render('search', {title: "Search", results: [], searched: true, num: nested_num, query: req.query.query});
      }
    });
  }
});
示例#25
0
var express = require('express');
var router = express.Router();

var basex = require('basex');
var client = new basex.Session("127.0.0.1", 1984, "admin", "admin");
client.execute("OPEN Colenso");

router.get('/', function(req, res, next) {
    var searchString = req.query.text;
    var containsText = ' . contains text '

    console.log(searchString)
    client.execute(
        "XQUERY declare default element namespace 'http://www.tei-c.org/ns/1.0';" +
        "for $n in .//TEI[. contains text "+searchString+"]\n"+
        " return db:path($n)",
        function (error, result){
            if(error){
                console.error(error);
            }
            else{
                var results = result.result
                results = results.split('\n')
                var resultCount = results.length
                res.render('stringResults', {
                    title: 'Colenso Project Search Text',
                    results:results,
                    resultCount:resultCount,
                    searchString:searchString
                });
            }
示例#26
0
var getAuthorList = function(){
	client("xquery //name", listifyResult);
	console.log('open data : ' + client.state);
};