GitHub PullRequestReviewCommentEvent at 2014-08-08 19:49:18
Repository: cassovary
Actor: szymonm
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/twitter/cassovary/pulls/comments/16012750","id":16012750,"diff_hunk":"@@ -0,0 +1,107 @@\n+/*\n+ * Copyright 2014 Twitter, Inc.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n+ * file except in compliance with the License. You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software distributed\n+ * under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR\n+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the\n+ * specific language governing permissions and limitations under the License.\n+ */\n+\n+package com.twitter.cassovary.util\n+\n+import scala.concurrent.ExecutionContext.Implicits.global\n+import com.twitter.app.Flags\n+import com.twitter.logging.Logger\n+import java.io.File\n+import scala.Some\n+import scala.concurrent._\n+import scala.concurrent.duration.Duration\n+\n+/**\n+ * General schema for processing multiple files (in our case wikipedia dumps)\n+ * and combining results from their processing.\n+ *\n+ * Reads information from a list of files, processes every file with\n+ * [processFile] function (implemented in subclass) and combines\n+ * results from all files using [combineResults] (default implementation\n+ * waits for first phase finish only).\n+ *\n+ * @param name Program name to be used by `flags`.\n+ * @tparam R Result of processing single file.\n+ */\n+abstract class FilesProcessor[R](name: String) {\n+  private val log = Logger.get(\"Files processor\")\n+\n+\n+  val flags = new Flags(name)\n+  val fileFlag = flags[String](\"f\", \"Filename of a single file to read from\")\n+  val directoryFlag = flags[String](\"d\", \"Directory to read all xml files from\")\n+  val outputFlag = flags[String](\"o\", \"Output filename to write to\")\n+  val extensionFlag = flags[String](\"e\", \".ids\", \"Extension of file to write to \" +\n+    \"(when processing multiple files.)\")\n+  val helpFlag = flags(\"h\", false, \"Print usage\")\n+\n+  def apply(args: Array[String]) {\n+    flags.parse(args)\n+\n+    if (helpFlag()) {\n+      println(flags.usage)\n+    } else {\n+      directoryFlag.get match {\n+        case Some(dirName) =>\n+          val dir = new File(dirName)\n+          val filesInDir = dir.list()\n+          if (filesInDir == null) {\n+            throw new Exception(\"Current directory is \" + System.getProperty(\"user.dir\") +\n+              \" and nothing was found in dir \" + dir)\n+          }\n+          if (filesInDir.isEmpty) {\n+            log.warning(\"Empty directory.\")\n+          }\n+          val futures: Array[Future[R]] = filesInDir\n+            .filter(f => f.endsWith(\"xml\"))\n+            .map {\n+            file =>\n+              future {\n+                try {\n+                  processFile(dir + \"/\" + file, Some(dirName + \"/\" +\n+                    file.replace(\".xml\", extensionFlag())))\n+                } catch {\n+                  case e: Exception => throw new Exception(\"Exception thrown, when \" +\n+                    \"extracting file: \" + file, e)\n+                }\n+              }\n+          }\n+          combineResults(futures.toSeq)\n+        case None =>\n+          val res = processFile(fileFlag(), Some(outputFlag()))\n+          combineResults(Seq(Future.successful(res)))\n+      }\n+    }\n+  }\n+\n+  def processFile(inputFilename: String, outputFilename: Option[String]): R\n+\n+  /**\n+   * Combines results from file processing phase.\n+   *\n+   * Default implementation only waits for all the files to be\n+   * processed. For each failed processing puts warning to the log\n+   * and ignores the failure.\n+   */\n+  def combineResults(partialResutls: Seq[Future[R]]): Unit = {\n+    val failedIgnored = partialResutls.map {\n+      f: Future[R] => f.map(x => ()).recover {","path":"cassovary-wikipedia/src/main/scala/com/twitter/cassovary/util/FilesProcessor.scala","position":99,"original_position":99,"commit_id":"820b4a53eeee8833d7b14c0cb1c6c37dae3efdb4","original_commit_id":"820b4a53eeee8833d7b14c0cb1c6c37dae3efdb4","user":{"login":"szymonm","id":5087912,"avatar_url":"https://avatars.githubusercontent.com/u/5087912?v=2","gravatar_id":"1a64987a53a17dbc3782afba665350bc","url":"https://api.github.com/users/szymonm","html_url":"https://github.com/szymonm","followers_url":"https://api.github.com/users/szymonm/followers","following_url":"https://api.github.com/users/szymonm/following{/other_user}","gists_url":"https://api.github.com/users/szymonm/gists{/gist_id}","starred_url":"https://api.github.com/users/szymonm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szymonm/subscriptions","organizations_url":"https://api.github.com/users/szymonm/orgs","repos_url":"https://api.github.com/users/szymonm/repos","events_url":"https://api.github.com/users/szymonm/events{/privacy}","received_events_url":"https://api.github.com/users/szymonm/received_events","type":"User","site_admin":false},"body":"Changes Future[R] into Future[Unit], so I can recover it with ().\r\nAny better way to log error and ignore failed futures?","created_at":"2014-08-08T19:49:18Z","updated_at":"2014-08-08T19:49:18Z","html_url":"https://github.com/twitter/cassovary/pull/77#discussion_r16012750","pull_request_url":"https://api.github.com/repos/twitter/cassovary/pulls/77","_links":{"self":{"href":"https://api.github.com/repos/twitter/cassovary/pulls/comments/16012750"},"html":{"href":"https://github.com/twitter/cassovary/pull/77#discussion_r16012750"},"pull_request":{"href":"https://api.github.com/repos/twitter/cassovary/pulls/77"}}},"pull_request":{"url":"https://api.github.com/repos/twitter/cassovary/pulls/77","id":17483423,"html_url":"https://github.com/twitter/cassovary/pull/77","diff_url":"https://github.com/twitter/cassovary/pull/77.diff","patch_url":"https://github.com/twitter/cassovary/pull/77.patch","issue_url":"https://api.github.com/repos/twitter/cassovary/issues/77","number":77,"state":"open","title":"Reading wikipedia","user":{"login":"szymonm","id":5087912,"avatar_url":"https://avatars.githubusercontent.com/u/5087912?v=2","gravatar_id":"1a64987a53a17dbc3782afba665350bc","url":"https://api.github.com/users/szymonm","html_url":"https://github.com/szymonm","followers_url":"https://api.github.com/users/szymonm/followers","following_url":"https://api.github.com/users/szymonm/following{/other_user}","gists_url":"https://api.github.com/users/szymonm/gists{/gist_id}","starred_url":"https://api.github.com/users/szymonm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szymonm/subscriptions","organizations_url":"https://api.github.com/users/szymonm/orgs","repos_url":"https://api.github.com/users/szymonm/repos","events_url":"https://api.github.com/users/szymonm/events{/privacy}","received_events_url":"https://api.github.com/users/szymonm/received_events","type":"User","site_admin":false},"body":"This commit contains basic tools to load Wikipedia graph to Cassovary:\r\n\r\n1. RedirectsExtractor - tool to parse Wikipedia dumps and get all redirects to a single file.\r\n2. DumpToGraphConverter - tool to parse Wikipedia dumps and print links graph as adjacency list for Cassovary\r\n3. HashMapsBasedWikipediaGraph - classes that read Wikipedia graph and redirects from previous tools and store them in a graph and hash table.\r\n\r\nUsing this code it's possible to load Wikipedia to Cassovary. Steps take following times (on server class machine):\r\n1. Redirects - 2000s\r\n2. Dumps to Graph - 1800s\r\n3. Reading - 304 s.","created_at":"2014-06-23T16:13:28Z","updated_at":"2014-08-08T19:49:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"36d0531d3280afe85cdca6d949215452ce592083","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/twitter/cassovary/pulls/77/commits","review_comments_url":"https://api.github.com/repos/twitter/cassovary/pulls/77/comments","review_comment_url":"https://api.github.com/repos/twitter/cassovary/pulls/comments/{number}","comments_url":"https://api.github.com/repos/twitter/cassovary/issues/77/comments","statuses_url":"https://api.github.com/repos/twitter/cassovary/statuses/820b4a53eeee8833d7b14c0cb1c6c37dae3efdb4","head":{"label":"szymonm:wikipediaConversion","ref":"wikipediaConversion","sha":"820b4a53eeee8833d7b14c0cb1c6c37dae3efdb4","user":{"login":"szymonm","id":5087912,"avatar_url":"https://avatars.githubusercontent.com/u/5087912?v=2","gravatar_id":"1a64987a53a17dbc3782afba665350bc","url":"https://api.github.com/users/szymonm","html_url":"https://github.com/szymonm","followers_url":"https://api.github.com/users/szymonm/followers","following_url":"https://api.github.com/users/szymonm/following{/other_user}","gists_url":"https://api.github.com/users/szymonm/gists{/gist_id}","starred_url":"https://api.github.com/users/szymonm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szymonm/subscriptions","organizations_url":"https://api.github.com/users/szymonm/orgs","repos_url":"https://api.github.com/users/szymonm/repos","events_url":"https://api.github.com/users/szymonm/events{/privacy}","received_events_url":"https://api.github.com/users/szymonm/received_events","type":"User","site_admin":false},"repo":{"id":17590418,"name":"cassovary","full_name":"szymonm/cassovary","owner":{"login":"szymonm","id":5087912,"avatar_url":"https://avatars.githubusercontent.com/u/5087912?v=2","gravatar_id":"1a64987a53a17dbc3782afba665350bc","url":"https://api.github.com/users/szymonm","html_url":"https://github.com/szymonm","followers_url":"https://api.github.com/users/szymonm/followers","following_url":"https://api.github.com/users/szymonm/following{/other_user}","gists_url":"https://api.github.com/users/szymonm/gists{/gist_id}","starred_url":"https://api.github.com/users/szymonm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szymonm/subscriptions","organizations_url":"https://api.github.com/users/szymonm/orgs","repos_url":"https://api.github.com/users/szymonm/repos","events_url":"https://api.github.com/users/szymonm/events{/privacy}","received_events_url":"https://api.github.com/users/szymonm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/szymonm/cassovary","description":"Cassovary is a simple big graph processing library for the JVM","fork":true,"url":"https://api.github.com/repos/szymonm/cassovary","forks_url":"https://api.github.com/repos/szymonm/cassovary/forks","keys_url":"https://api.github.com/repos/szymonm/cassovary/keys{/key_id}","collaborators_url":"https://api.github.com/repos/szymonm/cassovary/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/szymonm/cassovary/teams","hooks_url":"https://api.github.com/repos/szymonm/cassovary/hooks","issue_events_url":"https://api.github.com/repos/szymonm/cassovary/issues/events{/number}","events_url":"https://api.github.com/repos/szymonm/cassovary/events","assignees_url":"https://api.github.com/repos/szymonm/cassovary/assignees{/user}","branches_url":"https://api.github.com/repos/szymonm/cassovary/branches{/branch}","tags_url":"https://api.github.com/repos/szymonm/cassovary/tags","blobs_url":"https://api.github.com/repos/szymonm/cassovary/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/szymonm/cassovary/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/szymonm/cassovary/git/refs{/sha}","trees_url":"https://api.github.com/repos/szymonm/cassovary/git/trees{/sha}","statuses_url":"https://api.github.com/repos/szymonm/cassovary/statuses/{sha}","languages_url":"https://api.github.com/repos/szymonm/cassovary/languages","stargazers_url":"https://api.github.com/repos/szymonm/cassovary/stargazers","contributors_url":"https://api.github.com/repos/szymonm/cassovary/contributors","subscribers_url":"https://api.github.com/repos/szymonm/cassovary/subscribers","subscription_url":"https://api.github.com/repos/szymonm/cassovary/subscription","commits_url":"https://api.github.com/repos/szymonm/cassovary/commits{/sha}","git_commits_url":"https://api.github.com/repos/szymonm/cassovary/git/commits{/sha}","comments_url":"https://api.github.com/repos/szymonm/cassovary/comments{/number}","issue_comment_url":"https://api.github.com/repos/szymonm/cassovary/issues/comments/{number}","contents_url":"https://api.github.com/repos/szymonm/cassovary/contents/{+path}","compare_url":"https://api.github.com/repos/szymonm/cassovary/compare/{base}...{head}","merges_url":"https://api.github.com/repos/szymonm/cassovary/merges","archive_url":"https://api.github.com/repos/szymonm/cassovary/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/szymonm/cassovary/downloads","issues_url":"https://api.github.com/repos/szymonm/cassovary/issues{/number}","pulls_url":"https://api.github.com/repos/szymonm/cassovary/pulls{/number}","milestones_url":"https://api.github.com/repos/szymonm/cassovary/milestones{/number}","notifications_url":"https://api.github.com/repos/szymonm/cassovary/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/szymonm/cassovary/labels{/name}","releases_url":"https://api.github.com/repos/szymonm/cassovary/releases{/id}","created_at":"2014-03-10T11:24:08Z","updated_at":"2014-06-27T09:42:46Z","pushed_at":"2014-08-05T21:05:31Z","git_url":"git://github.com/szymonm/cassovary.git","ssh_url":"git@github.com:szymonm/cassovary.git","clone_url":"https://github.com/szymonm/cassovary.git","svn_url":"https://github.com/szymonm/cassovary","homepage":"http://twitter.com/cassovary","size":4001,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"twitter:master","ref":"master","sha":"40c214cabfe69db6acb05274a459896c1fe02633","user":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?v=2","gravatar_id":"2f4a8254d032a8ec5e4c48d461e54fcc","url":"https://api.github.com/users/twitter","html_url":"https://github.com/twitter","followers_url":"https://api.github.com/users/twitter/followers","following_url":"https://api.github.com/users/twitter/following{/other_user}","gists_url":"https://api.github.com/users/twitter/gists{/gist_id}","starred_url":"https://api.github.com/users/twitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twitter/subscriptions","organizations_url":"https://api.github.com/users/twitter/orgs","repos_url":"https://api.github.com/users/twitter/repos","events_url":"https://api.github.com/users/twitter/events{/privacy}","received_events_url":"https://api.github.com/users/twitter/received_events","type":"Organization","site_admin":false},"repo":{"id":3509388,"name":"cassovary","full_name":"twitter/cassovary","owner":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?v=2","gravatar_id":"2f4a8254d032a8ec5e4c48d461e54fcc","url":"https://api.github.com/users/twitter","html_url":"https://github.com/twitter","followers_url":"https://api.github.com/users/twitter/followers","following_url":"https://api.github.com/users/twitter/following{/other_user}","gists_url":"https://api.github.com/users/twitter/gists{/gist_id}","starred_url":"https://api.github.com/users/twitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twitter/subscriptions","organizations_url":"https://api.github.com/users/twitter/orgs","repos_url":"https://api.github.com/users/twitter/repos","events_url":"https://api.github.com/users/twitter/events{/privacy}","received_events_url":"https://api.github.com/users/twitter/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/twitter/cassovary","description":"Cassovary is a simple big graph processing library for the JVM","fork":false,"url":"https://api.github.com/repos/twitter/cassovary","forks_url":"https://api.github.com/repos/twitter/cassovary/forks","keys_url":"https://api.github.com/repos/twitter/cassovary/keys{/key_id}","collaborators_url":"https://api.github.com/repos/twitter/cassovary/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/twitter/cassovary/teams","hooks_url":"https://api.github.com/repos/twitter/cassovary/hooks","issue_events_url":"https://api.github.com/repos/twitter/cassovary/issues/events{/number}","events_url":"https://api.github.com/repos/twitter/cassovary/events","assignees_url":"https://api.github.com/repos/twitter/cassovary/assignees{/user}","branches_url":"https://api.github.com/repos/twitter/cassovary/branches{/branch}","tags_url":"https://api.github.com/repos/twitter/cassovary/tags","blobs_url":"https://api.github.com/repos/twitter/cassovary/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/twitter/cassovary/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/twitter/cassovary/git/refs{/sha}","trees_url":"https://api.github.com/repos/twitter/cassovary/git/trees{/sha}","statuses_url":"https://api.github.com/repos/twitter/cassovary/statuses/{sha}","languages_url":"https://api.github.com/repos/twitter/cassovary/languages","stargazers_url":"https://api.github.com/repos/twitter/cassovary/stargazers","contributors_url":"https://api.github.com/repos/twitter/cassovary/contributors","subscribers_url":"https://api.github.com/repos/twitter/cassovary/subscribers","subscription_url":"https://api.github.com/repos/twitter/cassovary/subscription","commits_url":"https://api.github.com/repos/twitter/cassovary/commits{/sha}","git_commits_url":"https://api.github.com/repos/twitter/cassovary/git/commits{/sha}","comments_url":"https://api.github.com/repos/twitter/cassovary/comments{/number}","issue_comment_url":"https://api.github.com/repos/twitter/cassovary/issues/comments/{number}","contents_url":"https://api.github.com/repos/twitter/cassovary/contents/{+path}","compare_url":"https://api.github.com/repos/twitter/cassovary/compare/{base}...{head}","merges_url":"https://api.github.com/repos/twitter/cassovary/merges","archive_url":"https://api.github.com/repos/twitter/cassovary/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/twitter/cassovary/downloads","issues_url":"https://api.github.com/repos/twitter/cassovary/issues{/number}","pulls_url":"https://api.github.com/repos/twitter/cassovary/pulls{/number}","milestones_url":"https://api.github.com/repos/twitter/cassovary/milestones{/number}","notifications_url":"https://api.github.com/repos/twitter/cassovary/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/twitter/cassovary/labels{/name}","releases_url":"https://api.github.com/repos/twitter/cassovary/releases{/id}","created_at":"2012-02-21T23:22:30Z","updated_at":"2014-08-05T11:18:33Z","pushed_at":"2014-08-05T06:12:38Z","git_url":"git://github.com/twitter/cassovary.git","ssh_url":"git@github.com:twitter/cassovary.git","clone_url":"https://github.com/twitter/cassovary.git","svn_url":"https://github.com/twitter/cassovary","homepage":"http://twitter.com/cassovary","size":4266,"stargazers_count":621,"watchers_count":621,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"forks_count":67,"mirror_url":null,"open_issues_count":12,"forks":67,"open_issues":12,"watchers":621,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/twitter/cassovary/pulls/77"},"html":{"href":"https://github.com/twitter/cassovary/pull/77"},"issue":{"href":"https://api.github.com/repos/twitter/cassovary/issues/77"},"comments":{"href":"https://api.github.com/repos/twitter/cassovary/issues/77/comments"},"review_comments":{"href":"https://api.github.com/repos/twitter/cassovary/pulls/77/comments"},"review_comment":{"href":"https://api.github.com/repos/twitter/cassovary/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/twitter/cassovary/pulls/77/commits"},"statuses":{"href":"https://api.github.com/repos/twitter/cassovary/statuses/820b4a53eeee8833d7b14c0cb1c6c37dae3efdb4"}}}}