如何调整此javascript文件以读取localhost上的数据。解析RDF任务 [英] How to tweak this javascript file to read in my data on localhost. parsing RDF task
问题描述
我正在使用此 Javascript RDF解析器。
在文档中说它相应地使用它:
In the documentation it says to use it accordingly:
getRDFURL(url,func,followSeeAlso )
从网址下载并解析RDF。
url是接收RDF的网址,使用完整网址,而不是相对网址,否则基本网址会出错。
func是一个在处理rdf时调用的javascript函数。
在解析器的文件,我发现了这个空变量:
In the file for the parser, I spied this empty variable:
var baseURL='';
我填写如下:
var baseURL='http://localhost:8888/demo/StackOverflow-Europe.rdf';
在我尝试过的 index.html
文件中以这种方式调用此解析脚本:
In my index.html
file I tried to call this parsing script in this way:
<!DOCTYPE html>
<meta charset='utf-8'>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<link rel='stylesheet' href='style.css'>
</head>
<body>
<!--
<script type='text/javascript' src='script.js'></script>
-->
<script type='text/javascript' src='parser.js'></script>
</body>
</html>
但最后......什么都没发生。
but finally... nothing happened.
我做错了什么?
我想这不是调用javascript文件的正确方法吗?是吗?或许还有另一个原因。
I guess that's not the right way to call javascript files? Is that it? Or maybe there's another reason.
我对Javascript不太熟悉。
I'm not so familiar with Javascript.
推荐答案
正如Jeen Broekstra在评论中所说,您在html文件中使用的行:
As Jeen Broekstra said in the comments, the line you use in your html file:
<script type='text/javascript' src='parser.js'></script>
只能用于加载rdf-parser库。
has to only purpose to load the the rdf-parser library.
您可以直接在主服务器上加载
You can load it directly on the main server
<script src="http://www.jibbering.com/rdf-parser/parser.js"></script>
并使用您自己的脚本。
and use your own script.
您可以使用官方演示作为起点:
You can use the official demo as a starter point:
<script type="text/javascript">
function demo() {
foafNS = "http://xmlns.com/foaf/0.1/";
myRDF = new RDF();
myRDF.getRDFURL('/foaf2.rdf', callback);
function callback() {
alert("http://jibbering.com/foaf2.rdf contains the following triples\n\n" + myRDF.toNTriples())
nm = myRDF.Match(null, null, foafNS + "name", "Jim Ley")
mbox = myRDF.getSingleObject(null, nm[0].subject, foafNS + "mbox", null)
alert("The e-mail address of Jim Ley is " + mbox)
}
}
document.write('<p>See demo using <a href="/foaf2.rdf">/foaf2.rdf</a> <button onclick="demo()">See Demo</button></p>')
</script>
-
new RDF()
允许您创建RDF实用程序对象 -
getRDFURL('/ foaf2.rdf',回调)
加载foaf2.rdf
file并将函数callback
设置为回调,即当rdf文件完全加载时调用此函数。 -
myRDF.toNTriples()
返回所有RDF三元组。 -
nm = myRDF.Match(null,null,foafNS +name,Jim Ley)
返回与主题/谓词/对象模式匹配的三元组数组。 -
mbox = myRDF.getSingleObject(null,nm [0] .subject,foafNS +mbox,null)
返回对象的值与主题/谓词/对象模式匹配的三元组的集合,如果未找到则为空字符串。 new RDF()
allows you to create an RDF utility objectgetRDFURL('/foaf2.rdf', callback)
loads thefoaf2.rdf
file and set the functioncallback
as a callback, i.e. this function is called when the rdf file has been completely loaded.myRDF.toNTriples()
returns all RDF triples.nm = myRDF.Match(null, null, foafNS + "name","Jim Ley")
returns an array of triples that match the subject/predicate/object pattern.mbox = myRDF.getSingleObject(null, nm[0].subject, foafNS + "mbox", null)
returns the value of the object in the collection of triples that matches the subject/predicate/object pattern, or an empty string if not found.
这篇关于如何调整此javascript文件以读取localhost上的数据。解析RDF任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!