2011年10月2日星期日

Use of microdata Schema.org in KRL

[]

In my blog, anonymous electronic trade entry: construction of a true quarter offer Kynetx applications, I mentioned that I used HTML microdata in the form of a Schema.org product microdata as a means of obtaining data from the product page to the app. Some people have asked for more details on.

Microdata, microformats and RDFa, is a means of encoding semantic mark-up in HTML. I am not going to try to adopt a position that is best for a particular job (see the results of a plugin of jQuery for processing of microdata wrote Philip Jagenstedt.) Modified it it a bit for my purposes:

I put two files juery.microdata.js and jquery.microdata.json.js together put the function in the second in the first.I've modified to work with runtime KRL enveloping them in a lock that applies to $K extend the copy included in runtime KRL of jQuery.

The end result was included in the RuleSet KRL, add the line below the block of metadata:

use resources of javascript "http://www.windley.com/want/jquery.microdata.js"

Place the button "I want" on the page through KRL action:

later ("buy_button #", want_button);

But instead of using the surveillance action to attach a listener to the button agent, issued the following JavaScript:

issue <$k("#want_button").click(function(){ var="" jsontext="$K.microdata.json(" [itemtype="http://schema.org/Product" ]");"="" var="" prodprops="jsonText.items[0].properties;" var="" offer="prodprops.offers[0].properties;" var="" seller="offer.seller[0].properties;" app="KOBJ.get_application(" a16x108");"="" app.raise_event("product_found",="" {"prodname":prodprops.name[0],="" "modelno":prodprops.model[0],="" "produrl":prodprops.url[0],="" "price":offer.price[0],="" "shipping":offer.shipping[0],="" "seller":json.stringify(seller.name[0],="" undefined,="" 2)="" });});="">>

Concluding two lines in this JavaScript cause an event to the KRL engine called product_found when you click on the button "I want". Events attributes are collected by the library of microdata. We have the JSON text using the $ function K.microdata.json which refers to the nodes in the DOM that have an attribute called itemtype that has the value http://schema.org/Product.

The reference returns an array of elements that have the right to itemtype. In my case, I only imported the first, so I'm referring to elements [0]. Note that data is organized hierarchically so that it matches the specification of product Schema.org microdata. I get the properties of the product from the first moment, get the offer and get the seller's offer.

The rule that responds to the event product_found simply extracts data from the event attributes

process_product rule {select when web product_found pre {price = event:param("price"); sending = event:param("shipping"); final_price = price + shipping;...}}...}

If more sites start semantic encoding microdata data, I'll be tempted to find a widespread form of access in KRL in the easiest way to do this would be to allow a specification to microdata in the action of monitoring, and then return all JSON KRL processing using expressions JSONPath. I would also like to enable the discovery, by which an event occurs when microdata are and what kind. Thus, for example, can automatically place a button "wants" on any page that has product microdata.

Posted by windley on July 11, 2011, 11: 58 AM

View the original article here

没有评论:

发表评论