forked from own-pt/cl-wnbrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagraph.lisp
73 lines (59 loc) · 2.18 KB
/
agraph.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
;; -*- mode: common-lisp -*-
;; Copyright (c) 2015,2016 The OpenWordNet-PT project
;; This program and the accompanying materials are made available
;; under the terms described in the LICENSE file.
(in-package :cl-wnbrowser)
(defun read-query (query-file)
(read-file-into-string (merge-pathnames query-file *basedir*)))
(defun make-agraph-query-uri ()
(format nil "~a/~a" *allegro-graph-url* *allegro-graph-repository*))
(defun call-allegro-graph (query)
(let ((stream
(nth-value 0 (drakma:http-request
(make-agraph-query-uri)
:accept "text/csv"
:method :post
:external-format-out :utf-8
:parameters (list (cons "query" query))
:want-stream nil))))
(cl-csv:read-csv stream :skip-first-p t)))
(defparameter *query-cache* (make-hash-table))
(defun initialize-stat-cache ()
(progn
(setf
(gethash :percent-complete *query-cache*)
'(("unknown" "0" "0" "0")))
(setf
(gethash :count-classes *query-cache*)
'(("http://arademaker.github.com/wn30/schema/unknown" "0" "0" "0")))))
(initialize-stat-cache)
(defun stats-percent-complete-query ()
(call-allegro-graph (read-query *query/by-lexfile*)))
(defun stats-count-classes-query ()
(call-allegro-graph (read-query *query/by-pos-pt*)))
(defun update-stat-cache ()
(progn
(setf
(gethash :percent-complete *query-cache*)
(stats-percent-complete-query))
(setf
(gethash :count-classes *query-cache*)
(stats-count-classes-query))))
(defun remove-schema-uri (uri)
(cl-ppcre:regex-replace *wn30-schema-uri* uri ""))
(defun stats-count-classes-plist ()
(list :rowscount (mapcar
(lambda (row)
(list :type (remove-schema-uri (first row))
:totalpt (parse-integer (second row))
:totalpr (parse-integer (third row))
:percent (parse-number (fourth row))))
(gethash :count-classes *query-cache*))))
(defun stats-percent-complete-plist ()
(list :rowspercent (mapcar
(lambda (row)
(list :lexfile (first row)
:totalpt (parse-integer (second row))
:totalpr (parse-integer (third row))
:percent (parse-number (fourth row))))
(gethash :percent-complete *query-cache*))))