使用Javascript从使用RDF序列化的数据中呈现表格

时间:2015-11-18 20:59:08

标签: javascript rdf semantic-web

我想要的是一个可以在表中输出数据的函数,如下所示:

enter image description here

作为一个起点,我有以下data table code,它可以从表格的CSV中准确地显示上面的图片:

"variable","aror","asd","maxdd"
"Convertible Arbitrage",0.0770203710991655,0.0694461870173684,-0.292688394529575
"CTA Global",0.0767109922711062,0.0870559916457339,-0.11676813742079
"Distressed Securities",0.0975096216543971,0.0635590261337229,-0.229232535454022
"Emerging Markets",0.0936124939942315,0.133615370977481,-0.359789528051813

要使它使用此功能:

function drawDataTableFromDsv(dataFile, fileDelimiter, suppressedHeaders, outputElementId) {

  var dsv = d3.dsv(fileDelimiter, "text/utf-8");  // plain
  dsv(dataFile, function(error, data) {
        if (error)
            return console.error(error);

    var dataHeaders = d3.keys(data[0]);
    dataHeaders = _.difference(dataHeaders, suppressedHeaders);
            console.log(dataHeaders)

        data.forEach(function (d, i) {
            //2015-05-13T01:21:07
            if (d.datePosted.trim() != "")
                d.datePosted = isoDateFormat.parse(d.datePosted);
        });

        tabulate(data, dataHeaders, outputElementId);
    });
}

到目前为止一切顺利,这里的事情变得有趣......

我不太关心这些数据,我关心的是RDF的文件,看起来像这样:

<?xml version="1.0" ?>
<rdf:RDF
xmlns:owl='http://www.w3.org/2002/07/owl#'
xmlns:edsa='http://www.edsa-project.eu/edsa#'
xmlns:pp='ftp://ftp-sop.inria.fr/wimmics/soft/pprint/'
xmlns:kg='http://ns.inria.fr/edelweiss/2010/kgram/'
xmlns:schema='http://schema.org/'
xmlns:geo='http://www.w3.org/2003/01/geo/wgs84_pos#'
xmlns:xml='http://www.w3.org/XML/1998/namespace'
xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:xsd='http://www.w3.org/2001/XMLSchema#'
xmlns:cos='http://www.inria.fr/acacia/corese#'
xmlns:geonames='http://www.geonames.org/ontology#'>

<rdf:Description rdf:about='http://sws.geonames.org/2867714/'>
 <geonames:alternateName xml:lang='tl'>Lungsod ng M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='rm'>Minca</geonames:alternateName>
 <geonames:alternateName xml:lang='pfl'>Minche</geonames:alternateName>
 <geonames:alternateName xml:lang='bar'>Minga</geonames:alternateName>
 <geonames:alternateName xml:lang='bs'>Minhen</geonames:alternateName>
 <geonames:alternateName xml:lang='hbs'>Minhen</geonames:alternateName>
 <geonames:alternateName xml:lang='lv'>Minhene</geonames:alternateName>
 <geonames:alternateName xml:lang='lt'>Miunchenas</geonames:alternateName>
 <geonames:alternateName xml:lang='cs'>Mnichov</geonames:alternateName>
 <geonames:alternateName xml:lang='hsb'>Mnichow</geonames:alternateName>
 <geonames:alternateName xml:lang='sk'>Mn&#237;chov</geonames:alternateName>
 <geonames:alternateName xml:lang='pl'>Monachium</geonames:alternateName>
 <geonames:alternateName xml:lang='sc'>Monaco de Baviera</geonames:alternateName>
 <geonames:alternateName xml:lang='vec'>Monaco de Baviera</geonames:alternateName>
 <geonames:alternateName xml:lang='it'>Monaco di Baviera</geonames:alternateName>
 <geonames:alternateName xml:lang='nap'>Monaco e Baviera</geonames:alternateName>
 <geonames:alternateName xml:lang='co'>Monacu di Baviera</geonames:alternateName>
 <geonames:alternateName xml:lang='la'>Monacum</geonames:alternateName>
 <geonames:alternateName xml:lang='uz'>Munhen</geonames:alternateName>
 <geonames:alternateName xml:lang='ca'>Munic</geonames:alternateName>
 <geonames:alternateName xml:lang='oc'>Munic</geonames:alternateName>
 <geonames:alternateName xml:lang='ast'>Munich</geonames:alternateName>
 <geonames:alternateName xml:lang='br'>Munich</geonames:alternateName>
 <geonames:alternateName xml:lang='en'>Munich</geonames:alternateName>
 <geonames:alternateName xml:lang='eu'>Munich</geonames:alternateName>
 <geonames:alternateName xml:lang='fr'>Munich</geonames:alternateName>
 <geonames:alternateName xml:lang='ilo'>Munich</geonames:alternateName>
 <geonames:alternateName xml:lang='ms'>Munich</geonames:alternateName>
 <geonames:alternateName xml:lang='nah'>Munich</geonames:alternateName>
 <geonames:alternateName xml:lang='pam'>Munich</geonames:alternateName>
 <geonames:alternateName xml:lang='sco'>Munich</geonames:alternateName>
 <geonames:alternateName xml:lang='tl'>Munich</geonames:alternateName>
 <geonames:alternateName xml:lang='tum'>Munich</geonames:alternateName>
 <geonames:alternateName xml:lang='war'>Munich</geonames:alternateName>
 <geonames:alternateName xml:lang='yo'>Munich</geonames:alternateName>
 <geonames:alternateName xml:lang='tet'>Munike</geonames:alternateName>
 <geonames:alternateName xml:lang='pt'>Munique</geonames:alternateName>
 <geonames:alternateName xml:lang='diq'>Munix</geonames:alternateName>
 <geonames:alternateName xml:lang='eo'>Munkeno</geonames:alternateName>
 <geonames:alternateName xml:lang='ku'>Mun&#238;h</geonames:alternateName>
 <geonames:alternateName xml:lang='sq'>Mynihu</geonames:alternateName>
 <geonames:alternateName xml:lang='ug'>Myunx&#233;n</geonames:alternateName>
 <geonames:alternateName xml:lang='scn'>M&#242;nacu</geonames:alternateName>
 <geonames:alternateName xml:lang='pms'>M&#249;nich &#235;d Baviera</geonames:alternateName>
 <geonames:alternateName xml:lang='gl'>M&#250;nic</geonames:alternateName>
 <geonames:alternateName xml:lang='an'>M&#250;nich</geonames:alternateName>
 <geonames:alternateName xml:lang='es'>M&#250;nich</geonames:alternateName>
 <geonames:alternateName xml:lang='ext'>M&#250;nich</geonames:alternateName>
 <geonames:alternateName xml:lang='gn'>M&#250;nich</geonames:alternateName>
 <geonames:alternateName xml:lang='af'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='br'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='da'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='de'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='et'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='fi'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='hr'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='hu'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='id'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='io'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='is'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='nds'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='nl'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='nn'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='no'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='pdc'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='ro'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='sl'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='sv'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='vi'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='vo'>M&#252;nchen</geonames:alternateName>
 <geonames:alternateName xml:lang='lmo'>M&#252;negh</geonames:alternateName>
 <geonames:alternateName xml:lang='az'>M&#252;nhen</geonames:alternateName>
 <geonames:alternateName xml:lang='tr'>M&#252;nih</geonames:alternateName>
 <geonames:alternateName xml:lang='el'>&#924;&#972;&#957;&#945;&#967;&#959;</geonames:alternateName>
 <geonames:alternateName xml:lang='be'>&#1043;&#1086;&#1088;&#1072;&#1076; &#1052;&#1102;&#1085;&#1093;&#1077;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='mk'>&#1052;&#1080;&#1085;&#1093;&#1077;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='sr'>&#1052;&#1080;&#1085;&#1093;&#1077;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='bg'>&#1052;&#1102;&#1085;&#1093;&#1077;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='cv'>&#1052;&#1102;&#1085;&#1093;&#1077;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='kk'>&#1052;&#1102;&#1085;&#1093;&#1077;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='mhr'>&#1052;&#1102;&#1085;&#1093;&#1077;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='mn'>&#1052;&#1102;&#1085;&#1093;&#1077;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='os'>&#1052;&#1102;&#1085;&#1093;&#1077;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='ru'>&#1052;&#1102;&#1085;&#1093;&#1077;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='tg'>&#1052;&#1102;&#1085;&#1093;&#1077;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='uk'>&#1052;&#1102;&#1085;&#1093;&#1077;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='tt'>&#1052;&#1199;&#1085;&#1093;&#1077;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='sah'>&#1052;&#1199;&#1085;&#1093;&#1101;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='mrj'>&#1052;&#1265;&#1085;&#1093;&#1077;&#1085;</geonames:alternateName>
 <geonames:alternateName xml:lang='hy'>&#1348;&#1397;&#1400;&#1410;&#1398;&#1389;&#1381;&#1398;</geonames:alternateName>
 <geonames:alternateName xml:lang='he'>&#1502;&#1497;&#1504;&#1499;&#1503;</geonames:alternateName>
 <geonames:alternateName xml:lang='yi'>&#1502;&#1497;&#1504;&#1499;&#1503;</geonames:alternateName>
 <geonames:alternateName xml:lang='fa'>&#1605;&#1608;&#1606;&#1740;&#1582;</geonames:alternateName>
 <geonames:alternateName xml:lang='ar'>&#1605;&#1610;&#1608;&#1606;&#1582;</geonames:alternateName>
 <geonames:alternateName xml:lang='arz'>&#1605;&#1610;&#1608;&#1606;&#1610;&#1582;</geonames:alternateName>
 <geonames:alternateName xml:lang='ckb'>&#1605;&#1740;&#1608;&#1606;&#1582;</geonames:alternateName>
 <geonames:alternateName xml:lang='pnb'>&#1605;&#1740;&#1608;&#1606;&#1582;</geonames:alternateName>
 <geonames:alternateName xml:lang='ur'>&#1605;&#1740;&#1608;&#1606;&#1582;</geonames:alternateName>
 <geonames:alternateName xml:lang='mr'>&#2350;&#2381;&#2351;&#2369;&#2344;&#2381;&#2358;&#2375;&#2344;</geonames:alternateName>
 <geonames:alternateName xml:lang='hi'>&#2350;&#2381;&#2351;&#2370;&#2344;&#2367;&#2326;</geonames:alternateName>
 <geonames:alternateName xml:lang='bn'>&#2478;&#2495;&#2441;&#2472;&#2495;&#2454;</geonames:alternateName>
 <geonames:alternateName xml:lang='ta'>&#2990;&#3007;&#2991;&#3010;&#2985;&#3007;&#2965;&#3021;</geonames:alternateName>
 <geonames:alternateName xml:lang='kn'>&#3246;&#3277;&#3247;&#3266;&#3240;&#3263;&#3221;&#3277;</geonames:alternateName>
 <geonames:alternateName xml:lang='th'>&#3617;&#3636;&#3623;&#3609;&#3636;&#3585;</geonames:alternateName>
 <geonames:alternateName xml:lang='my'>&#4121;&#4156;&#4144;&#4152;&#4116;&#4101;&#4154;&#4097;&#4155;&#4154;&#4121;&#4156;&#4141;&#4143;&#4151;</geonames:alternateName>
 <geonames:alternateName xml:lang='ka'>&#4315;&#4312;&#4323;&#4316;&#4334;&#4308;&#4316;&#4312;</geonames:alternateName>
 <geonames:alternateName xml:lang='xmf'>&#4315;&#4312;&#4323;&#4316;&#4334;&#4308;&#4316;&#4312;</geonames:alternateName>
 <geonames:alternateName xml:lang='ja'>&#12511;&#12517;&#12531;&#12504;&#12531;</geonames:alternateName>
 <geonames:alternateName xml:lang='zh'>&#24917;&#23612;&#40657;</geonames:alternateName>
 <geonames:alternateName xml:lang='ko'>&#48012;&#54760;</geonames:alternateName>
 <geonames:countryCode rdf:datatype='http://www.w3.org/2001/XMLSchema#string'>DE</geonames:countryCode>
 <geonames:featureClass rdf:resource='http://www.geonames.org/ontology#P'/>
 <geonames:featureCode rdf:resource='http://www.geonames.org/ontology#P.PPLA'/>
 <geonames:locationMap rdf:resource='http://www.geonames.org/2867714/munich.html'/>
 <geonames:name rdf:datatype='http://www.w3.org/2001/XMLSchema#string'>Munich</geonames:name>
 <geonames:nearbyFeatures rdf:resource='http://sws.geonames.org/2867714/nearby.rdf'/>
 <geonames:parentCountry rdf:resource='http://sws.geonames.org/2921044/'/>
 <geonames:population rdf:datatype='http://www.w3.org/2001/XMLSchema#string'>1260391</geonames:population>
 <geonames:wikipediaArticle rdf:resource='http://en.wikipedia.org/wiki/Munich'/>
 <rdf:type rdf:resource='http://www.geonames.org/ontology#Feature'/>
 <rdfs:isDefinedBy rdf:resource='http://sws.geonames.org/2867714/about.rdf'/>
 <rdfs:seeAlso rdf:resource='http://dbpedia.org/resource/Munich'/>
 <geo:lat rdf:datatype='http://www.w3.org/2001/XMLSchema#string'>48.13743</geo:lat>
 <geo:long rdf:datatype='http://www.w3.org/2001/XMLSchema#string'>11.57549</geo:long>
</rdf:Description>

<rdf:Description rdf:about='http://careers.stackoverflow.com/jobs/94342/engineering-systems-data-engineer-arm-ltd'>
 <schema:datePosted rdf:datatype='http://www.w3.org/2001/XMLSchema#Date'>2015-09-03T09:43:33+00:00</schema:datePosted>
 <schema:datePosted rdf:datatype='http://www.w3.org/2001/XMLSchema#Date'>2015-09-03T09:43:34+00:00</schema:datePosted>
 <schema:description rdf:datatype='http://www.w3.org/2001/XMLSchema#string'>&lt;p&gt;The Engineering Systems Analytics group is responsible for ensuring that we have a solid understanding of both our engineering infrastructure, which we refer to as the engineering systems stack, and the engineering processes that run on top of it.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;It strives to achieve this goal through a number of parallel activities:&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;By helping to refine our spark-based infrastructure that allows relevant data to be centrally collected, aggregated, and processed&lt;/li&gt;&lt;br /&gt;&lt;li&gt;By developing dashboards, reports and complex analysis and/or visualisations of the data that satisfy the business needs, both in terms of project reporting to help measure progress of the work, and in terms of infrastructure reporting to help understand the impact of this work on the estate&lt;/li&gt;&lt;br /&gt;&lt;li&gt;By working with engineering and IT functions to ensure sufficient relevant data is being captured to provide the best information in the above two categories&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;We are looking to augment the team with broad additional skills across the areas listed above.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;You will be a software engineer with experience of Spark and R, or equivalents.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;You will be equally at home working on the data processing pipeline, or performing an in depth analysis of the data it contains.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;You will consider yourself a data scientist, keen to tackle the problems of extracting knowledge from data, and driven to understand the core &amp;lsquo;stories&amp;rsquo; that data can tell, and to help drive efficiency and effectiveness improvements by providing the means to make data driven decisions.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;This role be based from ARM&apos;s HQ in Cambridge, UK.&lt;/p&gt;</schema:description>
 <schema:hiringOrganization rdf:datatype='http://www.w3.org/2001/XMLSchema#string'>ARM Ltd</schema:hiringOrganization>
 <schema:jobLocation rdf:datatype='http://www.w3.org/2001/XMLSchema#string'>Cambridge, UK</schema:jobLocation>
 <schema:jobTitle rdf:datatype='http://www.w3.org/2001/XMLSchema#string'>Engineering Systems Data Engineer at ARM Ltd (Cambridge, UK)</schema:jobTitle>
 <schema:source rdf:datatype='http://www.w3.org/2001/XMLSchema#string'>StackOverflow</schema:source>
 <schema:url rdf:resource='http://careers.stackoverflow.com/jobs/94342/engineering-systems-data-engineer-arm-ltd'/>
 <edsa:Location rdf:resource='http://sws.geonames.org/2653941/'/>
 <edsa:requiresSkill rdf:resource='http://www.edsa-project.eu/skill/apache-spark'/>
 <edsa:requiresSkill rdf:resource='http://www.edsa-project.eu/skill/hadoop'/>
 <edsa:requiresSkill rdf:resource='http://www.edsa-project.eu/skill/r'/>
 <edsa:requiresSkill rdf:resource='http://www.edsa-project.eu/skill/sql'/>
</rdf:Description>

我是否能够将该函数概括为接受RDF数据并将其输出到类似的样式表中?

我一直在研究rdfstore-js,但我还没能真正开始工作。

1 个答案:

答案 0 :(得分:1)

如果您将数据放入RDF数据库并查询它以获取要渲染的数据,我认为您最终会得到更易于维护和扩展的内容。

然后,对于您当前的用例,您可以通过SPARQL协议以CSV或TSV格式询问结果。