{"action":"created","comment":{"url":"https://api.github.com/repos/ontodia-org/ontodia/pulls/comments/139431728","pull_request_review_id":63035509,"id":139431728,"diff_hunk":"@@ -0,0 +1,261 @@\n+import {RDFStore, RDFGraph, createStore, createGraph, Node, Literal, NamedNode, Triple} from 'rdf-ext';\n+import {Dictionary} from '../model';\n+import {RDFCompositeParser} from './rdfCompositeParser';\n+\n+import {uniqueId} from 'lodash';\n+\n+const DEFAULT_STOREG_TYPE = 'text/turtle';\n+const DEFAULT_STOREG_URI = 'ontodiaLocalData';\n+\n+export function PrefixFactory(prefix: string): ((id: string) => string) {\n+    const lastSymbol = prefix[prefix.length - 1];\n+    const _prefix = lastSymbol === '/' || lastSymbol === '#' ? prefix : prefix + '/';\n+    return (id: string) => {\n+        return _prefix + id;\n+    };\n+}\n+\n+export interface RDFStore {\n+    add: (id: string, graph: RDFGraph) => void;\n+    match: (\n+        subject?: string,\n+        predicat?: string,\n+        object?: string,\n+        iri?: string,\n+        callback?: (result: any) => void,\n+        limit?: number,\n+    ) => Promise<RDFGraph>;\n+}\n+\n+export function isLiteral(el: Node): el is Literal {\n+    return el.interfaceName === 'Literal';\n+}\n+\n+export function isNamedNode(el: Node): el is NamedNode {\n+    return el.interfaceName === 'NamedNode';\n+}\n+\n+export type MatchStatement = {\n+    subject?: string,\n+    predicate?: string,\n+    object?: string,\n+    iri?: string,\n+    callback?: (...args: any[]) => void,\n+    limit?: number,\n+};\n+\n+export const LABEL_URIS = [\n+    'http://www.w3.org/2004/02/skos/core#prefLabel',\n+    'http://www.w3.org/2004/02/skos/core#label',\n+    'http://www.w3.org/2004/02/skos/core#altLabel',\n+    'http://www.w3.org/2000/01/rdf-schema#prefLabel',\n+    'http://www.w3.org/2000/01/rdf-schema#label',\n+    'http://xmlns.com/foaf/0.1/name',\n+    'http://schema.org/name',\n+];\n+\n+export const LABEL_POSTFIXES = [\n+    'prefLabel',\n+    'prefName',\n+    'label',\n+    'name',\n+    'title',\n+];\n+\n+export class RDFCacheableStore {\n+    private rdfStorage: RDFStore;\n+    private checkingElementMap: Dictionary<Promise<boolean>> = {};\n+    private labelsMap: Dictionary<Triple[]> = {};\n+    private countMap: Dictionary<number> = {};\n+    private elementTypes: Dictionary<Triple[]> = {};\n+    private prefs: { [id: string]: (id: string) => string };\n+    constructor(\n+        private parser: RDFCompositeParser,\n+    ) {\n+        this.rdfStorage = createStore();\n+        this.prefs = {\n+            RDF: PrefixFactory('http://www.w3.org/1999/02/22-rdf-syntax-ns#'),\n+            RDFS: PrefixFactory('http://www.w3.org/2000/01/rdf-schema#'),\n+            FOAF: PrefixFactory('http://xmlns.com/foaf/0.1/'),\n+            XSD: PrefixFactory('http://www.w3.org/2001/XMLSchema#'),\n+            OWL: PrefixFactory('http://www.w3.org/2002/07/owl#'),\n+        };\n+    }\n+\n+    add(rdfGraph: RDFGraph, prefix?: string) {\n+        this.rdfStorage.add(uniqueId(prefix) || (uniqueId(DEFAULT_STOREG_URI)), rdfGraph);\n+        this.enrichMaps(rdfGraph);\n+    }\n+\n+    match(\n+        subject?: string,\n+        predicate?: string,\n+        object?: string,\n+        iri?: string,\n+        callback?: (...args: any[]) => void,\n+        limit?: number,\n+    ): Promise<RDFGraph> {\n+        if (subject && (LABEL_URIS.indexOf(predicate) !== -1) && !object) {\n+            return Promise.resolve(this._getLabels(subject));\n+        } else if (subject && predicate === this.prefs.RDF('type') && !object) {\n+            return Promise.resolve(this.getTypes(subject));\n+        } else {\n+            return this.rdfStorage.match(\n+                subject,\n+                predicate,\n+                object,\n+                iri,\n+                callback,\n+                limit,\n+            );\n+        }\n+    }\n+\n+    matchAll(statements: MatchStatement[]): Promise<RDFGraph> {\n+        const slowQueries: MatchStatement[] = [];\n+        const queries: RDFGraph[] = [];\n+\n+        statements.forEach(statement => {\n+            if (statement.subject && (LABEL_URIS.indexOf(statement.predicate) !== -1) && !statement.object) {\n+                queries.push(this._getLabels(statement.subject));\n+            } else if (statement.subject && statement.predicate === this.prefs.RDF('type') && !statement.object) {\n+                queries.push(this.getTypes(statement.subject));\n+            } else {\n+                slowQueries.push(statement);\n+            }\n+        });\n+\n+        queries.push(this.multipleMatch(slowQueries));\n+\n+        return Promise.resolve(this.combineGraphs(queries));\n+    }\n+\n+    getLabels(id: string): Promise<RDFGraph> {\n+        return Promise.resolve(createGraph(this.labelsMap[id]));\n+    }\n+\n+    // Checks whetger the element is in the storage.\n+    checkElement(id: string): Promise<boolean> {\n+        if (this.labelsMap[id]) { // if there is label for an id then the element is already fetched\n+            return Promise.resolve(true);\n+        } else {\n+            if (!this.checkingElementMap[id]) {\n+                this.checkingElementMap[id] = this.rdfStorage.match(id, null, null).then(result => {\n+                    const resultArray = result.toArray();\n+                    if (resultArray.length === 0) {","path":"src/ontodia/data/rdf/rdfCacheableStore.ts","position":145,"original_position":145,"commit_id":"9dac3213083d5eceb95f46e6e54f700f810273ae","original_commit_id":"9dac3213083d5eceb95f46e6e54f700f810273ae","user":{"login":"AlexeyMz","id":1636942,"avatar_url":"https://avatars3.githubusercontent.com/u/1636942?v=4","gravatar_id":"","url":"https://api.github.com/users/AlexeyMz","html_url":"https://github.com/AlexeyMz","followers_url":"https://api.github.com/users/AlexeyMz/followers","following_url":"https://api.github.com/users/AlexeyMz/following{/other_user}","gists_url":"https://api.github.com/users/AlexeyMz/gists{/gist_id}","starred_url":"https://api.github.com/users/AlexeyMz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlexeyMz/subscriptions","organizations_url":"https://api.github.com/users/AlexeyMz/orgs","repos_url":"https://api.github.com/users/AlexeyMz/repos","events_url":"https://api.github.com/users/AlexeyMz/events{/privacy}","received_events_url":"https://api.github.com/users/AlexeyMz/received_events","type":"User","site_admin":false},"body":"You should replace this with just `return this.length !== 0;`","created_at":"2017-09-18T14:05:16Z","updated_at":"2017-09-18T14:17:38Z","html_url":"https://github.com/ontodia-org/ontodia/pull/71#discussion_r139431728","pull_request_url":"https://api.github.com/repos/ontodia-org/ontodia/pulls/71","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/ontodia-org/ontodia/pulls/comments/139431728"},"html":{"href":"https://github.com/ontodia-org/ontodia/pull/71#discussion_r139431728"},"pull_request":{"href":"https://api.github.com/repos/ontodia-org/ontodia/pulls/71"}}},"pull_request":{"url":"https://api.github.com/repos/ontodia-org/ontodia/pulls/71","id":141056378,"html_url":"https://github.com/ontodia-org/ontodia/pull/71","diff_url":"https://github.com/ontodia-org/ontodia/pull/71.diff","patch_url":"https://github.com/ontodia-org/ontodia/pull/71.patch","issue_url":"https://api.github.com/repos/ontodia-org/ontodia/issues/71","number":71,"state":"open","locked":false,"title":"Implementation of RDF data provider.","user":{"login":"Ladone3","id":2486371,"avatar_url":"https://avatars2.githubusercontent.com/u/2486371?v=4","gravatar_id":"","url":"https://api.github.com/users/Ladone3","html_url":"https://github.com/Ladone3","followers_url":"https://api.github.com/users/Ladone3/followers","following_url":"https://api.github.com/users/Ladone3/following{/other_user}","gists_url":"https://api.github.com/users/Ladone3/gists{/gist_id}","starred_url":"https://api.github.com/users/Ladone3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ladone3/subscriptions","organizations_url":"https://api.github.com/users/Ladone3/orgs","repos_url":"https://api.github.com/users/Ladone3/repos","events_url":"https://api.github.com/users/Ladone3/events{/privacy}","received_events_url":"https://api.github.com/users/Ladone3/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-09-14T12:08:38Z","updated_at":"2017-09-18T14:17:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4264efacc9b451740c834a2dcedef94b819dc795","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/ontodia-org/ontodia/pulls/71/commits","review_comments_url":"https://api.github.com/repos/ontodia-org/ontodia/pulls/71/comments","review_comment_url":"https://api.github.com/repos/ontodia-org/ontodia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ontodia-org/ontodia/issues/71/comments","statuses_url":"https://api.github.com/repos/ontodia-org/ontodia/statuses/9dac3213083d5eceb95f46e6e54f700f810273ae","head":{"label":"ontodia-org:rdf-dp-data-fetching","ref":"rdf-dp-data-fetching","sha":"9dac3213083d5eceb95f46e6e54f700f810273ae","user":{"login":"ontodia-org","id":12547575,"avatar_url":"https://avatars0.githubusercontent.com/u/12547575?v=4","gravatar_id":"","url":"https://api.github.com/users/ontodia-org","html_url":"https://github.com/ontodia-org","followers_url":"https://api.github.com/users/ontodia-org/followers","following_url":"https://api.github.com/users/ontodia-org/following{/other_user}","gists_url":"https://api.github.com/users/ontodia-org/gists{/gist_id}","starred_url":"https://api.github.com/users/ontodia-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ontodia-org/subscriptions","organizations_url":"https://api.github.com/users/ontodia-org/orgs","repos_url":"https://api.github.com/users/ontodia-org/repos","events_url":"https://api.github.com/users/ontodia-org/events{/privacy}","received_events_url":"https://api.github.com/users/ontodia-org/received_events","type":"Organization","site_admin":false},"repo":{"id":68012490,"name":"ontodia","full_name":"ontodia-org/ontodia","owner":{"login":"ontodia-org","id":12547575,"avatar_url":"https://avatars0.githubusercontent.com/u/12547575?v=4","gravatar_id":"","url":"https://api.github.com/users/ontodia-org","html_url":"https://github.com/ontodia-org","followers_url":"https://api.github.com/users/ontodia-org/followers","following_url":"https://api.github.com/users/ontodia-org/following{/other_user}","gists_url":"https://api.github.com/users/ontodia-org/gists{/gist_id}","starred_url":"https://api.github.com/users/ontodia-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ontodia-org/subscriptions","organizations_url":"https://api.github.com/users/ontodia-org/orgs","repos_url":"https://api.github.com/users/ontodia-org/repos","events_url":"https://api.github.com/users/ontodia-org/events{/privacy}","received_events_url":"https://api.github.com/users/ontodia-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ontodia-org/ontodia","description":"Ontodia data diagraming library","fork":false,"url":"https://api.github.com/repos/ontodia-org/ontodia","forks_url":"https://api.github.com/repos/ontodia-org/ontodia/forks","keys_url":"https://api.github.com/repos/ontodia-org/ontodia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ontodia-org/ontodia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ontodia-org/ontodia/teams","hooks_url":"https://api.github.com/repos/ontodia-org/ontodia/hooks","issue_events_url":"https://api.github.com/repos/ontodia-org/ontodia/issues/events{/number}","events_url":"https://api.github.com/repos/ontodia-org/ontodia/events","assignees_url":"https://api.github.com/repos/ontodia-org/ontodia/assignees{/user}","branches_url":"https://api.github.com/repos/ontodia-org/ontodia/branches{/branch}","tags_url":"https://api.github.com/repos/ontodia-org/ontodia/tags","blobs_url":"https://api.github.com/repos/ontodia-org/ontodia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ontodia-org/ontodia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ontodia-org/ontodia/git/refs{/sha}","trees_url":"https://api.github.com/repos/ontodia-org/ontodia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ontodia-org/ontodia/statuses/{sha}","languages_url":"https://api.github.com/repos/ontodia-org/ontodia/languages","stargazers_url":"https://api.github.com/repos/ontodia-org/ontodia/stargazers","contributors_url":"https://api.github.com/repos/ontodia-org/ontodia/contributors","subscribers_url":"https://api.github.com/repos/ontodia-org/ontodia/subscribers","subscription_url":"https://api.github.com/repos/ontodia-org/ontodia/subscription","commits_url":"https://api.github.com/repos/ontodia-org/ontodia/commits{/sha}","git_commits_url":"https://api.github.com/repos/ontodia-org/ontodia/git/commits{/sha}","comments_url":"https://api.github.com/repos/ontodia-org/ontodia/comments{/number}","issue_comment_url":"https://api.github.com/repos/ontodia-org/ontodia/issues/comments{/number}","contents_url":"https://api.github.com/repos/ontodia-org/ontodia/contents/{+path}","compare_url":"https://api.github.com/repos/ontodia-org/ontodia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ontodia-org/ontodia/merges","archive_url":"https://api.github.com/repos/ontodia-org/ontodia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ontodia-org/ontodia/downloads","issues_url":"https://api.github.com/repos/ontodia-org/ontodia/issues{/number}","pulls_url":"https://api.github.com/repos/ontodia-org/ontodia/pulls{/number}","milestones_url":"https://api.github.com/repos/ontodia-org/ontodia/milestones{/number}","notifications_url":"https://api.github.com/repos/ontodia-org/ontodia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ontodia-org/ontodia/labels{/name}","releases_url":"https://api.github.com/repos/ontodia-org/ontodia/releases{/id}","deployments_url":"https://api.github.com/repos/ontodia-org/ontodia/deployments","created_at":"2016-09-12T13:42:57Z","updated_at":"2017-08-24T18:27:48Z","pushed_at":"2017-09-15T12:33:16Z","git_url":"git://github.com/ontodia-org/ontodia.git","ssh_url":"git@github.com:ontodia-org/ontodia.git","clone_url":"https://github.com/ontodia-org/ontodia.git","svn_url":"https://github.com/ontodia-org/ontodia","homepage":null,"size":1957,"stargazers_count":24,"watchers_count":24,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":6,"forks":7,"open_issues":6,"watchers":24,"default_branch":"master"}},"base":{"label":"ontodia-org:master","ref":"master","sha":"3a3b261f815efa2c8daccf9d0aee86bda14249d0","user":{"login":"ontodia-org","id":12547575,"avatar_url":"https://avatars0.githubusercontent.com/u/12547575?v=4","gravatar_id":"","url":"https://api.github.com/users/ontodia-org","html_url":"https://github.com/ontodia-org","followers_url":"https://api.github.com/users/ontodia-org/followers","following_url":"https://api.github.com/users/ontodia-org/following{/other_user}","gists_url":"https://api.github.com/users/ontodia-org/gists{/gist_id}","starred_url":"https://api.github.com/users/ontodia-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ontodia-org/subscriptions","organizations_url":"https://api.github.com/users/ontodia-org/orgs","repos_url":"https://api.github.com/users/ontodia-org/repos","events_url":"https://api.github.com/users/ontodia-org/events{/privacy}","received_events_url":"https://api.github.com/users/ontodia-org/received_events","type":"Organization","site_admin":false},"repo":{"id":68012490,"name":"ontodia","full_name":"ontodia-org/ontodia","owner":{"login":"ontodia-org","id":12547575,"avatar_url":"https://avatars0.githubusercontent.com/u/12547575?v=4","gravatar_id":"","url":"https://api.github.com/users/ontodia-org","html_url":"https://github.com/ontodia-org","followers_url":"https://api.github.com/users/ontodia-org/followers","following_url":"https://api.github.com/users/ontodia-org/following{/other_user}","gists_url":"https://api.github.com/users/ontodia-org/gists{/gist_id}","starred_url":"https://api.github.com/users/ontodia-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ontodia-org/subscriptions","organizations_url":"https://api.github.com/users/ontodia-org/orgs","repos_url":"https://api.github.com/users/ontodia-org/repos","events_url":"https://api.github.com/users/ontodia-org/events{/privacy}","received_events_url":"https://api.github.com/users/ontodia-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ontodia-org/ontodia","description":"Ontodia data diagraming library","fork":false,"url":"https://api.github.com/repos/ontodia-org/ontodia","forks_url":"https://api.github.com/repos/ontodia-org/ontodia/forks","keys_url":"https://api.github.com/repos/ontodia-org/ontodia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ontodia-org/ontodia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ontodia-org/ontodia/teams","hooks_url":"https://api.github.com/repos/ontodia-org/ontodia/hooks","issue_events_url":"https://api.github.com/repos/ontodia-org/ontodia/issues/events{/number}","events_url":"https://api.github.com/repos/ontodia-org/ontodia/events","assignees_url":"https://api.github.com/repos/ontodia-org/ontodia/assignees{/user}","branches_url":"https://api.github.com/repos/ontodia-org/ontodia/branches{/branch}","tags_url":"https://api.github.com/repos/ontodia-org/ontodia/tags","blobs_url":"https://api.github.com/repos/ontodia-org/ontodia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ontodia-org/ontodia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ontodia-org/ontodia/git/refs{/sha}","trees_url":"https://api.github.com/repos/ontodia-org/ontodia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ontodia-org/ontodia/statuses/{sha}","languages_url":"https://api.github.com/repos/ontodia-org/ontodia/languages","stargazers_url":"https://api.github.com/repos/ontodia-org/ontodia/stargazers","contributors_url":"https://api.github.com/repos/ontodia-org/ontodia/contributors","subscribers_url":"https://api.github.com/repos/ontodia-org/ontodia/subscribers","subscription_url":"https://api.github.com/repos/ontodia-org/ontodia/subscription","commits_url":"https://api.github.com/repos/ontodia-org/ontodia/commits{/sha}","git_commits_url":"https://api.github.com/repos/ontodia-org/ontodia/git/commits{/sha}","comments_url":"https://api.github.com/repos/ontodia-org/ontodia/comments{/number}","issue_comment_url":"https://api.github.com/repos/ontodia-org/ontodia/issues/comments{/number}","contents_url":"https://api.github.com/repos/ontodia-org/ontodia/contents/{+path}","compare_url":"https://api.github.com/repos/ontodia-org/ontodia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ontodia-org/ontodia/merges","archive_url":"https://api.github.com/repos/ontodia-org/ontodia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ontodia-org/ontodia/downloads","issues_url":"https://api.github.com/repos/ontodia-org/ontodia/issues{/number}","pulls_url":"https://api.github.com/repos/ontodia-org/ontodia/pulls{/number}","milestones_url":"https://api.github.com/repos/ontodia-org/ontodia/milestones{/number}","notifications_url":"https://api.github.com/repos/ontodia-org/ontodia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ontodia-org/ontodia/labels{/name}","releases_url":"https://api.github.com/repos/ontodia-org/ontodia/releases{/id}","deployments_url":"https://api.github.com/repos/ontodia-org/ontodia/deployments","created_at":"2016-09-12T13:42:57Z","updated_at":"2017-08-24T18:27:48Z","pushed_at":"2017-09-15T12:33:16Z","git_url":"git://github.com/ontodia-org/ontodia.git","ssh_url":"git@github.com:ontodia-org/ontodia.git","clone_url":"https://github.com/ontodia-org/ontodia.git","svn_url":"https://github.com/ontodia-org/ontodia","homepage":null,"size":1957,"stargazers_count":24,"watchers_count":24,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":6,"forks":7,"open_issues":6,"watchers":24,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ontodia-org/ontodia/pulls/71"},"html":{"href":"https://github.com/ontodia-org/ontodia/pull/71"},"issue":{"href":"https://api.github.com/repos/ontodia-org/ontodia/issues/71"},"comments":{"href":"https://api.github.com/repos/ontodia-org/ontodia/issues/71/comments"},"review_comments":{"href":"https://api.github.com/repos/ontodia-org/ontodia/pulls/71/comments"},"review_comment":{"href":"https://api.github.com/repos/ontodia-org/ontodia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ontodia-org/ontodia/pulls/71/commits"},"statuses":{"href":"https://api.github.com/repos/ontodia-org/ontodia/statuses/9dac3213083d5eceb95f46e6e54f700f810273ae"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"AlexeyMz"}}