【原文写于2008-05-05 到 2008-05-10】
I will try to use this wiki as a blogging tool.
{{BlogInfo
|page=Blog:Baojie
|title=A Blog test
|visitor=Jie Bao
|date=2008/05/05 01:16:38 AM EDT
|tag=Jie’s Words
}}
I get the basic idea on how to implement semantic blogging on the top of semantic wiki.
If an application — may not necessarily be an enterprise application — can be implemented by a relational database, then it can be implemented on a semantic wiki.
{{BlogInfo
|page=Blog:Baojie
|title=Semantic Blogging
|visitor=User:Baojie
|date=2008/05/09 02:51:24 PM EDT
|tag=Semantic Blog,Jie’s Words
}}
很久没有灌水。很久不写Blog,也在于没有一个Blog系统是我喜欢的。这个基于semantic wiki的blog,因为是自己搭的,自己喜欢,就再写一点。现在可以做到每个用户X能且只能编辑自己的Blog (在Blog:X之下的页面)。
我觉得这会发展成一个挺好的东西。[[Zemanta]]之类,不适合我。[[Twine]]我也不喜欢,没有真正的语义,主要是自然语言理解的东西。语义博客,当然要有一点本体,简单的也好。我不认为现在有任何一个Blog可以真正称为semantic blog的,虽然这个词出来有几年了。
{{BlogInfo
|page=Blog:Baojie
|title=接着灌水:语义博客
|visitor=User:Baojie
|date=2008/05/10 03:52:21 AM EDT
|tag=Semantic Wiki, Semantic Blog,Jie’s Words
}}
刚刚更新了一下回复机制。实验一下。应该每个用户的回复也成为自己Blog的一部分
{{BlogInfo
|page=Blog:Baojie
|title=刚刚更新了一下回复机制
|visitor=User:Baojie
|date=2008/05/10 05:01:29 AM EDT
|tag=Jie’s Words
}}
有十年没用C了吧。从Hello World开始复习
习题代码在这里 http://codepad.org/users/baojie
资源:
基本功
链表 Linked List
树 Tree
数组和字符串
递归
I/O
未分类
call PHP from XSLT [ XSLTProcessor->registerPHPFunctions() ]
<?php
$xml = <<<EOB
<all><user>bob</user></all>
EOB;
$xsl = <<<EOB
<?xml version=”1.0″ encoding=”UTF-8″?>
<xsl:stylesheet version=”2.0″
xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”
xmlns:php=”http://php.net/xsl”>
<xsl:output method=”txt” encoding=”utf-8″ indent=”yes”/>
<xsl:template match=”all”>
<xsl:for-each select=”user”>
<xsl:value-of select=”php:function(‘ucfirst’,string(.))”/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
EOB;
$xmldoc = DOMDocument::loadXML($xml);
$xsldoc = DOMDocument::loadXML($xsl);
$proc = new XSLTProcessor();
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsldoc);
echo $proc->transformToXML($xmldoc);
?>
This article gives some typical SPARQL queries I used for getting familiar with an ontology which is only accessible by a querying endpoint.
1. Classes used
SELECT count(?x) ?type
WHERE{
?x a ?type.
}
GROUP BY ?type
2. OWL Classes
Sometime also need to find instances of rdfs:Class
SELECT ?x
WHERE{
?x a owl:Class .
}LIMIT 100
Instance counting
SELECT count(?y) ?x
WHERE{
?x a owl:Class .
?y a ?x .
}
GROUP BY ?x
3. Class Hierarchy
SELECT ?s ?o
WHERE{
?s rdfs:subClassOf ?o .
}
LIMIT 100
4. Properties used
SELECT DISTINCT ?p
WHERE{
?x ?p ?o .
}
ORDER BY ASC(?p)
LIMIT 100
5. Property Axioms
Domains and ranges
SELECT ?s ?domain ?range
WHERE{
?s a rdf:Property .
?s rdfs:domain ?domain .
?s rdfs:range ?range .
}
ORDER BY ?p
LIMIT 100
Inverse Properties
SELECT *
WHERE{
?p1 owl:inverseOf ?p2 .
}
ORDER BY ?p1
LIMIT 100
6. Instances (Triples)
Total triples:
SELECT count(*)
WHERE{
?s ?p ?o .
}
Triples by property
SELECT (count(*) AS ?c) ?p
WHERE{
?s ?p ?o .
}
GROUP BY ?p
ORDER BY ?c
7. Class Slots
Example query
SELECT DISTINCT ?p
WHERE{
?s a loticoowl:Member .
?s ?p ?o .
}
ORDER BY ?p
LIMIT 100
Some properties are used by instances with no class membership
SELECT DISTINCT ?p
WHERE{
?s ?p ?o .
OPTIONAL { ?s a ?x }
FILTER ( ! bound(?x) )
}
References:
目前支持了RIF-Core
代码很简单,目前乱七八糟的。可以读XML格式的输入,做presentation syntax的输出。正在做LP(logic program)格式的输出(这样就可以用LP的推理机来做推理),还没搞完。
使用的例子:
require_once("../rif2pres.php");
require_once("../rif2lp.php");
// parse XML syntax
$rifdoc = new RifDocument();
$rifdoc->load("ex8.rif");
// write in presentation syntax
$writer = new Rif2Presentation();
$writer->writeAnnotation = true;
$syntax = $writer->toPresentationSyntax($rifdoc);
echo $syntax;
//write in LP syntax
$writer = new Rif2LP();
$writer->toLP($rifdoc);
//print_r($writer->getLP());
echo $writer->getLP()->toString();
如果有兴趣参与,请和我联系(baojie@gmail.com)
SVN在这里
http://php-rif.svn.sourceforge.net/