Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved some stuff around.

  • Loading branch information...
commit 5144ccbc3dcf26b52696efbc8af4296c9707b2c0 1 parent e2869b4
@eedeebee eedeebee authored
View
42 answers_parser.rb
@@ -1,42 +0,0 @@
-require 'rexml/document'
-
-Dir.mkdir("#{ARGV[1]}/answers") unless File.directory?(ARGV[1] + "/answers")
-
-File.open(ARGV[0]) do |answers_file|
- # read until we find the first row
- line = answers_file.readline
- until line =~ /row/
- line = answers_file.readline
- end
-
- count = 1
- begin
- while line && line =~ /row/
- answer = REXML::Document.new(line)
- tags = answer.root.attributes["Tags"].gsub(/["\[\]]/, "").split(",")
- answer_xml = <<BEGIN
- <answer xmlns="http://marklogic.com/windycity">
- <id>#{answer.root.attributes["Id"].strip}</id>
- <creation_date>#{answer.root.attributes["CreationDate"]}</creation_date>
- <owner_id>#{answer.root.attributes["OwnerUserId"]}</owner_id>
-<parent_id>#{answer.root.attributes["ParentId"]}</parent_id>
- <body>#{answer.root.attributes["Body"].gsub(/[\r\n]/,"")}</body>
-BEGIN
- answer_xml << "<tags>" unless tags.empty?
- tags.each do |tag|
- answer_xml << "<tag>#{tag.strip}</tag>"
- end
- answer_xml << "</tags>" unless tags.empty?
- answer_xml << "</answer>"
- File.open("#{ARGV[1]}/answers/answer#{count}.xml", 'w') do |file|
- file.write answer_xml
- end
- count = count +1
- line = answers_file.readline
- end
- rescue EOFError
- # done
- end
-
-
-end
View
36 comments_parser.rb
@@ -1,36 +0,0 @@
-require 'rexml/document'
-
-Dir.mkdir("#{ARGV[1]}/comments") unless File.directory?(ARGV[1] + "/comments")
-
-File.open(ARGV[0]) do |comments_file|
- # read until we find the first row
- line = comments_file.readline
- until line =~ /row/
- line = comments_file.readline
- end
-
- count = 1
- begin
- while line && line =~ /row/
- comment = REXML::Document.new(line)
- comment_xml = <<BEGIN
- <comment xmlns="http://marklogic.com/windycity">
- <id>#{comment.root.attributes["Id"].strip}</id>
- <creation_date>#{comment.root.attributes["CreationDate"]}</creation_date>
- <user_id>#{comment.root.attributes["UserId"]}</user_id>
- <post_id>#{comment.root.attributes["PostId"]}</post_id>
- <body>#{comment.root.attributes["Body"].gsub(/[\r\n]/,"")}</body>
-BEGIN
- comment_xml << "</comment>"
- File.open("#{ARGV[1]}/comments/comment#{count}.xml", 'w') do |file|
- file.write comment_xml
- end
- count = count +1
- line = comments_file.readline
- end
- rescue EOFError
- # done
- end
-
-
-end
View
BIN  marklogic-data.tar.gz
Binary file not shown
View
12 marklogic/XQuery/dynamic_dispatch.xqy
@@ -0,0 +1,12 @@
+xquery version "1.0-ml";
+declare namespace error = "http://marklogic.com/xdmp/error";
+try {
+ let $request := xdmp:get-request-field("request")
+ let $log := xdmp:log(fn:concat("Dynamic request received:",$request))
+ return xdmp:eval($request)
+}
+catch ($exception) {
+ let $error-message := $exception/error:message
+ let $error-response := xdmp:set-response-code(500, $error-message)
+ return $error-message
+}
View
42 marklogic/answers_parser.rb
@@ -1,42 +0,0 @@
-require 'rexml/document'
-
-Dir.mkdir("#{ARGV[1]}/answers") unless File.directory?(ARGV[1] + "/answers")
-
-File.open(ARGV[0]) do |answers_file|
- # read until we find the first row
- line = answers_file.readline
- until line =~ /row/
- line = answers_file.readline
- end
-
- count = 1
- begin
- while line && line =~ /row/
- answer = REXML::Document.new(line)
- tags = answer.root.attributes["Tags"].gsub(/["\[\]]/, "").split(",")
- answer_xml = <<BEGIN
- <answer xmlns="http://marklogic.com/windycity">
- <identifier>#{answer.root.attributes["Id"].strip}</identifier>
- <creation_date>#{answer.root.attributes["CreationDate"]}</creation_date>
- <owner_id>#{answer.root.attributes["OwnerUserId"]}</owner_id>
-<parent_id>#{answer.root.attributes["ParentId"]}</parent_id>
- <body>#{answer.root.attributes["Body"].gsub(/[\r\n]/,"")}</body>
-BEGIN
- answer_xml << "<tags>" unless tags.empty?
- tags.each do |tag|
- answer_xml << "<tag>#{tag.strip}</tag>"
- end
- answer_xml << "</tags>" unless tags.empty?
- answer_xml << "</answer>"
- File.open("#{ARGV[1]}/answers/answer#{count}.xml", 'w') do |file|
- file.write answer_xml
- end
- count = count +1
- line = answers_file.readline
- end
- rescue EOFError
- # done
- end
-
-
-end
View
36 marklogic/comments_parser.rb
@@ -1,36 +0,0 @@
-require 'rexml/document'
-
-Dir.mkdir("#{ARGV[1]}/comments") unless File.directory?(ARGV[1] + "/comments")
-
-File.open(ARGV[0]) do |comments_file|
- # read until we find the first row
- line = comments_file.readline
- until line =~ /row/
- line = comments_file.readline
- end
-
- count = 1
- begin
- while line && line =~ /row/
- comment = REXML::Document.new(line)
- comment_xml = <<BEGIN
- <comment xmlns="http://marklogic.com/windycity">
- <identifier>#{comment.root.attributes["Id"].strip}</identifier>
- <creation_date>#{comment.root.attributes["CreationDate"]}</creation_date>
- <user_id>#{comment.root.attributes["UserId"]}</user_id>
- <post_id>#{comment.root.attributes["PostId"]}</post_id>
- <body>#{comment.root.attributes["Body"].gsub(/[\r\n]/,"")}</body>
-BEGIN
- comment_xml << "</comment>"
- File.open("#{ARGV[1]}/comments/comment#{count}.xml", 'w') do |file|
- file.write comment_xml
- end
- count = count +1
- line = comments_file.readline
- end
- rescue EOFError
- # done
- end
-
-
-end
View
8 marklogic/convert.sh
@@ -1,8 +0,0 @@
-#!/bin/sh
-
-for i in "answers comments posts" ; do
- ruby ${i}"_parser.rb" "data/"{$i}".xml" marklogic-data
-done
-
-zip -r marklogic-data.zip marklogic-data
-
View
BIN  marklogic/marklogic-data.tar.gz
Binary file not shown
View
41 marklogic/post_parser.rb
@@ -1,41 +0,0 @@
-require 'rexml/document'
-
-Dir.mkdir("#{ARGV[1]}/posts") unless File.directory?(ARGV[1] + "/posts")
-
-File.open(ARGV[0]) do |posts_file|
- # read until we find the first row
- line = posts_file.readline
- until line =~ /row/
- line = posts_file.readline
- end
-
- count = 1
- begin
- while line && line =~ /row/
- post = REXML::Document.new(line)
- tags = post.root.attributes["Tags"].gsub(/["\[\]]/, "").split(",")
- post_xml = <<BEGIN
- <post xmlns="http://marklogic.com/windycity">
- <id>#{post.root.attributes["Id"].strip}</id>
- <creation_date>#{post.root.attributes["CreationDate"]}</creation_date>
- <owner_id>#{post.root.attributes["OwnerUserId"]}</owner_id>
- <body>#{post.root.attributes["Body"].gsub(/[\r\n]/,"")}</body>
-BEGIN
- post_xml << "<tags>" unless tags.empty?
- tags.each do |tag|
- post_xml << "<tag>#{tag.strip}</tag>"
- end
- post_xml << "</tags>" unless tags.empty?
- post_xml << "</post>"
- File.open("#{ARGV[1]}/posts/post#{count}.xml", 'w') do |file|
- file.write post_xml
- end
- count = count +1
- line = posts_file.readline
- end
- rescue EOFError
- # done
- end
-
-
-end
View
41 marklogic/posts_parser.rb
@@ -1,41 +0,0 @@
-require 'rexml/document'
-
-Dir.mkdir("#{ARGV[1]}/posts") unless File.directory?(ARGV[1] + "/posts")
-
-File.open(ARGV[0]) do |posts_file|
- # read until we find the first row
- line = posts_file.readline
- until line =~ /row/
- line = posts_file.readline
- end
-
- count = 1
- begin
- while line && line =~ /row/
- post = REXML::Document.new(line)
- tags = post.root.attributes["Tags"].gsub(/["\[\]]/, "").split(",")
- post_xml = <<BEGIN
- <post xmlns="http://marklogic.com/windycity">
- <identifier>#{post.root.attributes["Id"].strip}</identifier>
- <creation_date>#{post.root.attributes["CreationDate"]}</creation_date>
- <owner_id>#{post.root.attributes["OwnerUserId"]}</owner_id>
- <body>#{post.root.attributes["Body"].gsub(/[\r\n]/,"")}</body>
-BEGIN
- post_xml << "<tags>" unless tags.empty?
- tags.each do |tag|
- post_xml << "<tag>#{tag.strip}</tag>"
- end
- post_xml << "</tags>" unless tags.empty?
- post_xml << "</post>"
- File.open("#{ARGV[1]}/posts/post#{count}.xml", 'w') do |file|
- file.write post_xml
- end
- count = count +1
- line = posts_file.readline
- end
- rescue EOFError
- # done
- end
-
-
-end
View
33 marklogic/user_parser.rb
@@ -1,33 +0,0 @@
-require 'rexml/document'
-
-Dir.mkdir("#{ARGV[1]}/users") unless File.directory?(ARGV[1] + "/users")
-
-File.open(ARGV[0]) do |users_file|
- # read until we find the first row
- line = users_file.readline
- until line =~ /row/
- line = users_file.readline
- end
-
- count = 1
- begin
- while line && line =~ /row/
- user = REXML::Document.new(line)
- user_xml = <<BEGIN
- <user xmlns="http://marklogic.com/windycity">
- <id>#{user.root.attributes["Id"].strip}</id>
- <display_name>#{user.root.attributes["DisplayName"]}</display_name>
-BEGIN
- user_xml << "</user>"
- File.open("#{ARGV[1]}/users/user#{count}.xml", 'w') do |file|
- file.write user_xml
- end
- count = count +1
- line = users_file.readline
- end
- rescue EOFError
- # done
- end
-
-
-end
View
33 marklogic/users_parser.rb
@@ -1,33 +0,0 @@
-require 'rexml/document'
-
-Dir.mkdir("#{ARGV[1]}/users") unless File.directory?(ARGV[1] + "/users")
-
-File.open(ARGV[0]) do |users_file|
- # read until we find the first row
- line = users_file.readline
- until line =~ /row/
- line = users_file.readline
- end
-
- count = 1
- begin
- while line && line =~ /row/
- user = REXML::Document.new(line)
- user_xml = <<BEGIN
- <user xmlns="http://marklogic.com/windycity">
- <identifier>#{user.root.attributes["Id"].strip}</identifier>
- <display_name>#{user.root.attributes["DisplayName"]}</display_name>
-BEGIN
- user_xml << "</user>"
- File.open("#{ARGV[1]}/users/user#{count}.xml", 'w') do |file|
- file.write user_xml
- end
- count = count +1
- line = users_file.readline
- end
- rescue EOFError
- # done
- end
-
-
-end
View
41 post_parser.rb
@@ -1,41 +0,0 @@
-require 'rexml/document'
-
-Dir.mkdir("#{ARGV[1]}/posts") unless File.directory?(ARGV[1] + "/posts")
-
-File.open(ARGV[0]) do |posts_file|
- # read until we find the first row
- line = posts_file.readline
- until line =~ /row/
- line = posts_file.readline
- end
-
- count = 1
- begin
- while line && line =~ /row/
- post = REXML::Document.new(line)
- tags = post.root.attributes["Tags"].gsub(/["\[\]]/, "").split(",")
- post_xml = <<BEGIN
- <post xmlns="http://marklogic.com/windycity">
- <id>#{post.root.attributes["Id"].strip}</id>
- <creation_date>#{post.root.attributes["CreationDate"]}</creation_date>
- <owner_id>#{post.root.attributes["OwnerUserId"]}</owner_id>
- <body>#{post.root.attributes["Body"].gsub(/[\r\n]/,"")}</body>
-BEGIN
- post_xml << "<tags>" unless tags.empty?
- tags.each do |tag|
- post_xml << "<tag>#{tag.strip}</tag>"
- end
- post_xml << "</tags>" unless tags.empty?
- post_xml << "</post>"
- File.open("#{ARGV[1]}/posts/post#{count}.xml", 'w') do |file|
- file.write post_xml
- end
- count = count +1
- line = posts_file.readline
- end
- rescue EOFError
- # done
- end
-
-
-end
View
33 user_parser.rb
@@ -1,33 +0,0 @@
-require 'rexml/document'
-
-Dir.mkdir("#{ARGV[1]}/users") unless File.directory?(ARGV[1] + "/users")
-
-File.open(ARGV[0]) do |users_file|
- # read until we find the first row
- line = users_file.readline
- until line =~ /row/
- line = users_file.readline
- end
-
- count = 1
- begin
- while line && line =~ /row/
- user = REXML::Document.new(line)
- user_xml = <<BEGIN
- <user xmlns="http://marklogic.com/windycity">
- <id>#{user.root.attributes["Id"].strip}</id>
- <display_name>#{user.root.attributes["DisplayName"]}</display_name>
-BEGIN
- user_xml << "</user>"
- File.open("#{ARGV[1]}/users/user#{count}.xml", 'w') do |file|
- file.write user_xml
- end
- count = count +1
- line = users_file.readline
- end
- rescue EOFError
- # done
- end
-
-
-end
Please sign in to comment.
Something went wrong with that request. Please try again.