{"action":"created","comment":{"url":"https://api.github.com/repos/dbpedia/extraction-framework/pulls/comments/28856110","id":28856110,"diff_hunk":"@@ -0,0 +1,280 @@\n+package org.dbpedia.extraction.scripts\n+\n+import org.dbpedia.extraction.ontology.io.OntologyReader\n+import org.dbpedia.extraction.util._\n+import org.dbpedia.extraction.sources.{XMLSource, WikiSource}\n+import org.dbpedia.extraction.util.RichFile\n+import java.net.{URI, URL}\n+import org.dbpedia.extraction.wikiparser.Namespace\n+import java.io._\n+import org.dbpedia.extraction.destinations.formatters.UriPolicy._\n+import org.dbpedia.extraction.util.RichFile._\n+import scala.collection.mutable.{ArrayBuffer, HashMap, MultiMap}\n+import scala.collection.mutable\n+import scala.Console._\n+import scala.Some\n+import org.dbpedia.extraction.destinations._\n+import org.dbpedia.extraction.destinations.formatters.Formatter\n+import org.dbpedia.extraction.util.IOUtils._\n+import scala.Some\n+import scala.Some\n+import scala.collection.parallel.mutable.ParTrieMap\n+import scala.collection.concurrent.TrieMap\n+import java.util.logging.{Logger, Level}\n+import scala.Some\n+import scala.Console\n+import scala.Some\n+import scala.Some\n+\n+/**\n+ * Normalize all triples into the new namespace using wikidata identifiers as base using\n+ * sameAs links between different projects.\n+ *\n+ * - read one or more triple files that contain the URI mapping (wikidata sameAs triples):\n+ *   - the predicate is ignored (only read owl:sameAs links and ignore the rest?)\n+ * - read one or more files that need to be normalized into the new namespace:\n+ *   - the predicate is ignored\n+ *\n+ * Example call:\n+ * ../run MapSubjectUris /data/dbpedia wikidata wikidata-sameas .nt.gz infobox-properties,page-links,... -normalized .nt.gz,.nq.gz 10000-\n+ *\n+ * The output name extension for triples, that are rejected because the subject does not exist, becomes\n+ * \\-normalized-subject-rejected, * and similarly for triples with non-existant objects it becomes -normalized-object-rejected,\n+ * where -normalized is the provided * output extension. Triples that have both subject and object missing from the mapping\n+ * are sent to the extension -normalized-rejected. No changes are made to rejected triples.\n+ *\n+ */\n+\n+object NormalizeDatasets {\n+\n+  private val logger = Logger.getLogger(classOf[NormalizationJob].getName)\n+\n+  private def split(arg: String): Array[String] = {\n+    arg.split(\",\").map(_.trim).filter(_.nonEmpty)\n+  }\n+\n+  // URI prefix for wikidata entities\n+  private val WikidataResource = \"http://wikidata.dbpedia.org/resource/Q\"\n+\n+  def main(args: Array[String]): Unit = {\n+    require(args != null && args.length >= 6,\n+      \"need at least six args: \" +\n+        /*0*/ \"extraction config file\" +\n+        /*1*/ \"prefix of mapping file (eg. wikidata)\"+\n+        /*2*/ \"comma-separated names of datasets mapping URIs to wikidata identifiers (eg. wikidata-sameas)\" +\n+        /*3*/ \"mapping file suffix (e.g. '.nt.gz', '.ttl', '.ttl.bz2'), \" +\n+        /*4*/ \"comma-separated names of input datasets (e.g. 'infobox-properties,mappingbased-properties'), \" +\n+        /*5*/ \"output dataset name extension (e.g. '-normalized'), \")\n+\n+\n+    val config = ConfigUtils.loadConfig(args(0), \"UTF-8\")\n+\n+    val baseDir = ConfigUtils.getValue(config, \"base-dir\", true)(new File(_))\n+    if (!baseDir.exists)\n+      throw new IllegalArgumentException(\"dir \" + baseDir + \" does not exist\")\n+    val langConfString = ConfigUtils.getString(config, \"languages\", false)\n+    val languages = ConfigUtils.parseLanguages(baseDir, Seq(langConfString))\n+    require(languages.nonEmpty, \"no languages\")\n+\n+    val formats = parseFormats(config, \"uri-policy\", \"format\")\n+\n+    val mappingPrefix = args(1)\n+\n+    val mappings = split(args(2))\n+    require(mappings.nonEmpty, \"no mapping datasets\")\n+\n+    // Suffix of mapping files, for example \".nt\", \".ttl.gz\", \".nt.bz2\" and so on.\n+    // This script works with .nt, .ttl, .nq or .tql files, using IRIs or URIs.\n+    val mappingSuffix = args(3)\n+    require(mappingSuffix.nonEmpty, \"no mapping file suffix\")\n+\n+    val inputs = split(args(4))\n+    require(inputs.nonEmpty, \"no input datasets\")\n+\n+    val outputExtension = args(5)\n+    require(outputExtension.nonEmpty, \"no output name extension\")\n+\n+    val extensions = List(outputExtension, outputExtension + \"-subject-rejected\", outputExtension + \"-object-rejected\", outputExtension + \"-rejected\")\n+\n+    // Suffixes of input/output files, for example \".nt\", \".ttl.gz\", \".nt.bz2\" and so on.\n+    // This script works with .nt, .ttl, .nq or .tql files, using IRIs or URIs.\n+    val suffixes = formats.keys.map(\".\" + _)\n+    require(suffixes.nonEmpty, \"no input/output file suffixes\")\n+\n+    // We really want to saturate CPUs and disk, so we use 50% more workers than CPUs\n+    val jobs = for(language <- languages) yield {\n+      val wikiFinder = new Finder(baseDir, language, \"wiki\") // Finds Wikipedia extracted datasets\n+      val date = wikiFinder.dates().last\n+      val datasets = for(input <- inputs; extension <- extensions) yield new Dataset(input + extension)\n+      val destination = createDestination(wikiFinder, date, formats, datasets)\n+      val mappingFinder = new DateFinder(baseDir, Language(mappingPrefix)) // Finds wikidata mapping dataset\n+\n+      val map = {\n+        // Try reading from cache\n+        val cache = wikiFinder.file(date, \"sameas-mappings.obj\")","path":"scripts/src/main/scala/org/dbpedia/extraction/scripts/NormalizeDatasets.scala","position":114,"original_position":114,"commit_id":"b1983b1f907dc7c74c08d8acdab0e34e9c3383b6","original_commit_id":"b1983b1f907dc7c74c08d8acdab0e34e9c3383b6","user":{"login":"jimkont","id":1047581,"avatar_url":"https://avatars.githubusercontent.com/u/1047581?v=3","gravatar_id":"","url":"https://api.github.com/users/jimkont","html_url":"https://github.com/jimkont","followers_url":"https://api.github.com/users/jimkont/followers","following_url":"https://api.github.com/users/jimkont/following{/other_user}","gists_url":"https://api.github.com/users/jimkont/gists{/gist_id}","starred_url":"https://api.github.com/users/jimkont/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jimkont/subscriptions","organizations_url":"https://api.github.com/users/jimkont/orgs","repos_url":"https://api.github.com/users/jimkont/repos","events_url":"https://api.github.com/users/jimkont/events{/privacy}","received_events_url":"https://api.github.com/users/jimkont/received_events","type":"User","site_admin":false},"body":"if the script is re-started with another language withouth deleting the file it will produce false results","created_at":"2015-04-22T09:20:29Z","updated_at":"2015-04-22T09:20:29Z","html_url":"https://github.com/dbpedia/extraction-framework/pull/380#discussion_r28856110","pull_request_url":"https://api.github.com/repos/dbpedia/extraction-framework/pulls/380","_links":{"self":{"href":"https://api.github.com/repos/dbpedia/extraction-framework/pulls/comments/28856110"},"html":{"href":"https://github.com/dbpedia/extraction-framework/pull/380#discussion_r28856110"},"pull_request":{"href":"https://api.github.com/repos/dbpedia/extraction-framework/pulls/380"}}},"pull_request":{"url":"https://api.github.com/repos/dbpedia/extraction-framework/pulls/380","id":33434281,"html_url":"https://github.com/dbpedia/extraction-framework/pull/380","diff_url":"https://github.com/dbpedia/extraction-framework/pull/380.diff","patch_url":"https://github.com/dbpedia/extraction-framework/pull/380.patch","issue_url":"https://api.github.com/repos/dbpedia/extraction-framework/issues/380","number":380,"state":"open","locked":false,"title":"Initial code for wikidata-based normalizer, untested","user":{"login":"nilesh-c","id":1786561,"avatar_url":"https://avatars.githubusercontent.com/u/1786561?v=3","gravatar_id":"","url":"https://api.github.com/users/nilesh-c","html_url":"https://github.com/nilesh-c","followers_url":"https://api.github.com/users/nilesh-c/followers","following_url":"https://api.github.com/users/nilesh-c/following{/other_user}","gists_url":"https://api.github.com/users/nilesh-c/gists{/gist_id}","starred_url":"https://api.github.com/users/nilesh-c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nilesh-c/subscriptions","organizations_url":"https://api.github.com/users/nilesh-c/orgs","repos_url":"https://api.github.com/users/nilesh-c/repos","events_url":"https://api.github.com/users/nilesh-c/events{/privacy}","received_events_url":"https://api.github.com/users/nilesh-c/received_events","type":"User","site_admin":false},"body":"Haven't tested this on sample data yet, mustn't merge. @chile12 could you check this?","created_at":"2015-04-16T09:47:17Z","updated_at":"2015-04-22T09:20:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"078711859e62872b9dd10a141e35aaca2f1ce12c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dbpedia/extraction-framework/pulls/380/commits","review_comments_url":"https://api.github.com/repos/dbpedia/extraction-framework/pulls/380/comments","review_comment_url":"https://api.github.com/repos/dbpedia/extraction-framework/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dbpedia/extraction-framework/issues/380/comments","statuses_url":"https://api.github.com/repos/dbpedia/extraction-framework/statuses/b1983b1f907dc7c74c08d8acdab0e34e9c3383b6","head":{"label":"nilesh-c:normalize","ref":"normalize","sha":"b1983b1f907dc7c74c08d8acdab0e34e9c3383b6","user":{"login":"nilesh-c","id":1786561,"avatar_url":"https://avatars.githubusercontent.com/u/1786561?v=3","gravatar_id":"","url":"https://api.github.com/users/nilesh-c","html_url":"https://github.com/nilesh-c","followers_url":"https://api.github.com/users/nilesh-c/followers","following_url":"https://api.github.com/users/nilesh-c/following{/other_user}","gists_url":"https://api.github.com/users/nilesh-c/gists{/gist_id}","starred_url":"https://api.github.com/users/nilesh-c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nilesh-c/subscriptions","organizations_url":"https://api.github.com/users/nilesh-c/orgs","repos_url":"https://api.github.com/users/nilesh-c/repos","events_url":"https://api.github.com/users/nilesh-c/events{/privacy}","received_events_url":"https://api.github.com/users/nilesh-c/received_events","type":"User","site_admin":false},"repo":{"id":18740126,"name":"extraction-framework","full_name":"nilesh-c/extraction-framework","owner":{"login":"nilesh-c","id":1786561,"avatar_url":"https://avatars.githubusercontent.com/u/1786561?v=3","gravatar_id":"","url":"https://api.github.com/users/nilesh-c","html_url":"https://github.com/nilesh-c","followers_url":"https://api.github.com/users/nilesh-c/followers","following_url":"https://api.github.com/users/nilesh-c/following{/other_user}","gists_url":"https://api.github.com/users/nilesh-c/gists{/gist_id}","starred_url":"https://api.github.com/users/nilesh-c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nilesh-c/subscriptions","organizations_url":"https://api.github.com/users/nilesh-c/orgs","repos_url":"https://api.github.com/users/nilesh-c/repos","events_url":"https://api.github.com/users/nilesh-c/events{/privacy}","received_events_url":"https://api.github.com/users/nilesh-c/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nilesh-c/extraction-framework","description":"The software used to extract structured data from Wikipedia","fork":true,"url":"https://api.github.com/repos/nilesh-c/extraction-framework","forks_url":"https://api.github.com/repos/nilesh-c/extraction-framework/forks","keys_url":"https://api.github.com/repos/nilesh-c/extraction-framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nilesh-c/extraction-framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nilesh-c/extraction-framework/teams","hooks_url":"https://api.github.com/repos/nilesh-c/extraction-framework/hooks","issue_events_url":"https://api.github.com/repos/nilesh-c/extraction-framework/issues/events{/number}","events_url":"https://api.github.com/repos/nilesh-c/extraction-framework/events","assignees_url":"https://api.github.com/repos/nilesh-c/extraction-framework/assignees{/user}","branches_url":"https://api.github.com/repos/nilesh-c/extraction-framework/branches{/branch}","tags_url":"https://api.github.com/repos/nilesh-c/extraction-framework/tags","blobs_url":"https://api.github.com/repos/nilesh-c/extraction-framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nilesh-c/extraction-framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nilesh-c/extraction-framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/nilesh-c/extraction-framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nilesh-c/extraction-framework/statuses/{sha}","languages_url":"https://api.github.com/repos/nilesh-c/extraction-framework/languages","stargazers_url":"https://api.github.com/repos/nilesh-c/extraction-framework/stargazers","contributors_url":"https://api.github.com/repos/nilesh-c/extraction-framework/contributors","subscribers_url":"https://api.github.com/repos/nilesh-c/extraction-framework/subscribers","subscription_url":"https://api.github.com/repos/nilesh-c/extraction-framework/subscription","commits_url":"https://api.github.com/repos/nilesh-c/extraction-framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/nilesh-c/extraction-framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/nilesh-c/extraction-framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/nilesh-c/extraction-framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/nilesh-c/extraction-framework/contents/{+path}","compare_url":"https://api.github.com/repos/nilesh-c/extraction-framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nilesh-c/extraction-framework/merges","archive_url":"https://api.github.com/repos/nilesh-c/extraction-framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nilesh-c/extraction-framework/downloads","issues_url":"https://api.github.com/repos/nilesh-c/extraction-framework/issues{/number}","pulls_url":"https://api.github.com/repos/nilesh-c/extraction-framework/pulls{/number}","milestones_url":"https://api.github.com/repos/nilesh-c/extraction-framework/milestones{/number}","notifications_url":"https://api.github.com/repos/nilesh-c/extraction-framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nilesh-c/extraction-framework/labels{/name}","releases_url":"https://api.github.com/repos/nilesh-c/extraction-framework/releases{/id}","created_at":"2014-04-13T21:13:25Z","updated_at":"2015-04-16T09:42:45Z","pushed_at":"2015-04-21T16:06:27Z","git_url":"git://github.com/nilesh-c/extraction-framework.git","ssh_url":"git@github.com:nilesh-c/extraction-framework.git","clone_url":"https://github.com/nilesh-c/extraction-framework.git","svn_url":"https://github.com/nilesh-c/extraction-framework","homepage":null,"size":50633,"stargazers_count":0,"watchers_count":0,"language":"Web Ontology Language","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dbpedia:master","ref":"master","sha":"a05b6d84ee7ddcc33258e2ae511a20d62ac291a7","user":{"login":"dbpedia","id":2864602,"avatar_url":"https://avatars.githubusercontent.com/u/2864602?v=3","gravatar_id":"","url":"https://api.github.com/users/dbpedia","html_url":"https://github.com/dbpedia","followers_url":"https://api.github.com/users/dbpedia/followers","following_url":"https://api.github.com/users/dbpedia/following{/other_user}","gists_url":"https://api.github.com/users/dbpedia/gists{/gist_id}","starred_url":"https://api.github.com/users/dbpedia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbpedia/subscriptions","organizations_url":"https://api.github.com/users/dbpedia/orgs","repos_url":"https://api.github.com/users/dbpedia/repos","events_url":"https://api.github.com/users/dbpedia/events{/privacy}","received_events_url":"https://api.github.com/users/dbpedia/received_events","type":"Organization","site_admin":false},"repo":{"id":8071225,"name":"extraction-framework","full_name":"dbpedia/extraction-framework","owner":{"login":"dbpedia","id":2864602,"avatar_url":"https://avatars.githubusercontent.com/u/2864602?v=3","gravatar_id":"","url":"https://api.github.com/users/dbpedia","html_url":"https://github.com/dbpedia","followers_url":"https://api.github.com/users/dbpedia/followers","following_url":"https://api.github.com/users/dbpedia/following{/other_user}","gists_url":"https://api.github.com/users/dbpedia/gists{/gist_id}","starred_url":"https://api.github.com/users/dbpedia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbpedia/subscriptions","organizations_url":"https://api.github.com/users/dbpedia/orgs","repos_url":"https://api.github.com/users/dbpedia/repos","events_url":"https://api.github.com/users/dbpedia/events{/privacy}","received_events_url":"https://api.github.com/users/dbpedia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dbpedia/extraction-framework","description":"The software used to extract structured data from Wikipedia","fork":false,"url":"https://api.github.com/repos/dbpedia/extraction-framework","forks_url":"https://api.github.com/repos/dbpedia/extraction-framework/forks","keys_url":"https://api.github.com/repos/dbpedia/extraction-framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dbpedia/extraction-framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dbpedia/extraction-framework/teams","hooks_url":"https://api.github.com/repos/dbpedia/extraction-framework/hooks","issue_events_url":"https://api.github.com/repos/dbpedia/extraction-framework/issues/events{/number}","events_url":"https://api.github.com/repos/dbpedia/extraction-framework/events","assignees_url":"https://api.github.com/repos/dbpedia/extraction-framework/assignees{/user}","branches_url":"https://api.github.com/repos/dbpedia/extraction-framework/branches{/branch}","tags_url":"https://api.github.com/repos/dbpedia/extraction-framework/tags","blobs_url":"https://api.github.com/repos/dbpedia/extraction-framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dbpedia/extraction-framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dbpedia/extraction-framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/dbpedia/extraction-framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dbpedia/extraction-framework/statuses/{sha}","languages_url":"https://api.github.com/repos/dbpedia/extraction-framework/languages","stargazers_url":"https://api.github.com/repos/dbpedia/extraction-framework/stargazers","contributors_url":"https://api.github.com/repos/dbpedia/extraction-framework/contributors","subscribers_url":"https://api.github.com/repos/dbpedia/extraction-framework/subscribers","subscription_url":"https://api.github.com/repos/dbpedia/extraction-framework/subscription","commits_url":"https://api.github.com/repos/dbpedia/extraction-framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/dbpedia/extraction-framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/dbpedia/extraction-framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/dbpedia/extraction-framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/dbpedia/extraction-framework/contents/{+path}","compare_url":"https://api.github.com/repos/dbpedia/extraction-framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dbpedia/extraction-framework/merges","archive_url":"https://api.github.com/repos/dbpedia/extraction-framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dbpedia/extraction-framework/downloads","issues_url":"https://api.github.com/repos/dbpedia/extraction-framework/issues{/number}","pulls_url":"https://api.github.com/repos/dbpedia/extraction-framework/pulls{/number}","milestones_url":"https://api.github.com/repos/dbpedia/extraction-framework/milestones{/number}","notifications_url":"https://api.github.com/repos/dbpedia/extraction-framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dbpedia/extraction-framework/labels{/name}","releases_url":"https://api.github.com/repos/dbpedia/extraction-framework/releases{/id}","created_at":"2013-02-07T11:00:28Z","updated_at":"2015-04-22T04:30:55Z","pushed_at":"2015-04-22T04:30:55Z","git_url":"git://github.com/dbpedia/extraction-framework.git","ssh_url":"git@github.com:dbpedia/extraction-framework.git","clone_url":"https://github.com/dbpedia/extraction-framework.git","svn_url":"https://github.com/dbpedia/extraction-framework","homepage":null,"size":57101,"stargazers_count":174,"watchers_count":174,"language":"Web Ontology Language","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":115,"mirror_url":null,"open_issues_count":68,"forks":115,"open_issues":68,"watchers":174,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dbpedia/extraction-framework/pulls/380"},"html":{"href":"https://github.com/dbpedia/extraction-framework/pull/380"},"issue":{"href":"https://api.github.com/repos/dbpedia/extraction-framework/issues/380"},"comments":{"href":"https://api.github.com/repos/dbpedia/extraction-framework/issues/380/comments"},"review_comments":{"href":"https://api.github.com/repos/dbpedia/extraction-framework/pulls/380/comments"},"review_comment":{"href":"https://api.github.com/repos/dbpedia/extraction-framework/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dbpedia/extraction-framework/pulls/380/commits"},"statuses":{"href":"https://api.github.com/repos/dbpedia/extraction-framework/statuses/b1983b1f907dc7c74c08d8acdab0e34e9c3383b6"}}}}