以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 Semantic Web(语义Web)/描述逻辑/本体 』 (http://bbs.xml.org.cn/list.asp?boardid=2) ---- 关于SPARQL的basic graph to SQL。 (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=79586) |
-- 作者:happy2009 -- 发布时间:1/21/2010 1:03:00 AM -- 关于SPARQL的basic graph to SQL。 01 Algorithm BGPtoSQL 02 Input: basic graph pattern BGP = (N;E) 03 Output: SQL query 04 Begin 05 Substitute each distinct blank node label in BGP with a unique variable /* unique for the scope of a SPARQL query */ 06 Assign each edge e 2 E a unique table alias te /*unique for the scope of a SPARQL query*/ 07 Construct the FROM clause to contain all the table aliases /*from += \Triples $te" for each e 2 E*/ 08 For each distinct variable v in BGP do /* Construct the SELECT clause */ 09 If v is a predicate variable then 10 Let e be the corresponding edge 11 select += \$te.predicate AS $e.label" 12 ElseIf v is an object variable then 13 Let e be the ¯rst incoming edge of the corresponding node n 14 select += \$te.object AS $n.label" 15 Else /* v is a subject variable */ 16 Let e be the ¯rst outgoing edge of the corresponding node n 17 select += \$te.subject AS $n.label" 18 End If 19 End For 20 For each RDF term (a URI or a literal) m in BGP do /* Construct the WHERE clause */ 21 If m is a predicate term then 22 Let e be the corresponding edge 23 where += \$te.predicate = $e.label AND " 24 Else /* m is an object or a subject term */ 25 Let n be the corresponding node 26 For each incoming edge e of n do 27 where += \$te.object = $n.label AND " End For 28 For each outgoing edge e of n do 29 where += \$te.subject = $n.label AND " End For 30 End If 31 End For 32 For each node n 2 N labeled with a variable do 33 If n.in-degree > 1 then /* Case 1 */ 34 Let ein 1 be the ¯rst incoming edge of n 35 For each incoming edge ein i of n and ein i 6= ein 1 do 36 where + = \$tein 1 .object = $tein i .object AND " End For 37 End If 38 If n.out-degree > 1 then /* Case 2 */ 39 Let eout 1 be the ¯rst outgoing edge of n 40 For each outgoing edge eout i of n and eout i 6= eout 1 do 41 where + = \$teout 1 .subject = $teout i .subject AND " End For 42 End If 43 If n.in-degree > 0 && n.out-degree > 0 then /* Case 3 */ 44 Let ein 1 be the ¯rst incoming edge of n; Let eout 1 be the ¯rst outgoing edge of n 45 where + = \$tein 1 .object = $teout 1 .subject AND " 46 End If 47 End For 48 For each distinct predicate variable and the corresponding edge e 2 E do 49 For each edge ei 2 E && ei 6= e && ei.label = e.label do /* Case 4 */ 50 where + = \$te.predicate = $tei .predicate AND " End For 51 For each node ni 2 N && ni.label = e.label do /* Case 5 */ 52 Let e1 be the ¯rst incoming/outgoing edge of ni /* `/' means `or' */ 53 where + = \$te.predicate = $te1 .object/subject AND " End For 54 End For 55 Return \SELECT" + select + \FROM" + from + \WHERE" + where 56 End Algorithm 请教各位:谁能解释一下6-19行?万分感谢! |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
31.250ms |