Bücher online kostenlos Kostenlos Online Lesen
Working With MediaWiki

Working With MediaWiki

Titel: Working With MediaWiki Kostenlos Bücher Online Lesen
Autoren: Yaron Koren
Vom Netzwerk:
the data is assumed to start at the very first line, while for ’CSV with header’, the first line holds the header information. JSON and XML are formats mostly associated with the web. GFF is used only for representing genomics data.
    The "data" parameter defines a series of what could be called mappings. A mapping sets a local variable to have the value of a tag or field in the source document with the given name. So, for instance if the URL being accessed holds XML that contains a section like "
Accounting
", and the #get_web_data call has the parameter "
data=department=dept
", then a local variable, "department", will get set to the value "Accounting". This will similarly work, for XML, if the relevant value is a tag attribute (instead of tag contents), e.g. something like "

".
    Handling XML documents can be tricky because their format can involve using the same generic tag or attribute name for different types of data. In the extreme case, you could imagine XML formatted like:




    In this case, each value is directly tied to an attribute called "name", so you can’t just use the attribute name, as you normally would with #get_web_data. Instead, you would need to use the longer chain of tag and attribute names pointing to each value, using a simple query language known as XPath. You can do that in #get_web_data, by adding the parameter “use xpath”. Here is how you could get the information from the previous example:
{{#get_web_data:url=http://example.com/employee_data.xml |format=xml |use xpath |data=employee=/employee/@name, department=/department/@name, position=/position/@name}}
    This problem of disambiguation can also occur with JSON data, and in fact there’s a syntax called JSONPath that does for JSON what XPath does for XML, but unfortunately External Data doesn’t support it.
    For CSV documents, the naming of fields depends on whether the file has a header row. If it does, i.e. it’s of ’CSV with header’ format, then each column gets the name assigned to it at the top; otherwise the names of the columns are just the sequential numbers 1, 2, 3 etc. For the basic ’CSV’ format, a mapping parameter could look like "
|data=department=4
".
    A #get_web_data call needs at least one value for the "data" parameter to be worthwhile; after all, some value needs to be set. By contrast, the "filters" parameter is optional. When used, the filters filter down the set of values in the accessed page by keeping only the row or rows of data that have the specified value(s) for the specified field name(s). For instance, if the file contains information about every employee, having a parameter like "
filters=name=Irving Ivanov
" will return only the row (if there is one) where the "name" field is set to "Irving Ivanov".
    This filtering system leaves a lot to be desired — there’s no way to match on substrings, for instance, or to use inequality operators for number fields. But in practice, that type of more complex filtering isn’t often needed, because the URLs being accessed are often part of a web-based API, where necessary filtering can often be done via the URL itself. Here’s an example of what such a call to an API could look like:
{{#get_web_data:
url=http://example.com/country_data_api?country=Morocco |format=json |data=population=Population}}
Displaying and storing values
    Once we have our local variables set, the next step is to display, or otherwise use them. How that’s done depends on whether there is one, or more than one, value for each variable. In the simple case, we have one value that’s been retrieved for each field. In that case, the parser function #external_value is used to display it on the screen. After the previous call to #get_web_data, for instance, the wikitext could contain the following:
The population of Morocco is {{#external_value: population}}.
    Assuming the "population" field was correctly retrieved before, this will insert a number into the text that’s displayed.
    If we want to also store the value as semantic data, so that it can be queried alongside the wiki’s native semantic data, that’s easy to do. If this call happens on a page called "Morocco", it’s just a matter of adding a Semantic MediaWiki tag:
The population of Morocco is [[Has population:: {{#external_value:population}}]].
    Storing external data via

Weitere Kostenlose Bücher