So I've managed to get past my issues, even without help! ;) Anyways, you knock one down, and another one pops up, isn't that how it usually is? So what i have done so far is that i put all the coordinates in a Container object instead. that solved the  one to many mapping, however now it seems that i can't retrieve the data when i try to query it through the #ask: parser function.

I have a page where i have defined the property [[Polygon::<coords>,<coords>....]], the page belongs to a category Polygon.

on the category page i have the following contents:

{{#ask: [[Category:Polygon]]
| ?Coordinates
| ?Polygon
| template=Oilfield-popup
| format=table

which draws a table on the cateogory page, however, the column with the polygon data is empty.

When digging in the sourcecode i can see that there is a call made to SMWResultArray::getNextDataValue(), this however seems to always return false instead of the expected container value when it comes to the polygon property. Can someone please explain why that is?


On Wed, May 23, 2012 at 2:23 PM, Kim Eik <> wrote:
Ok, so i figured out how to create the necessary table.. however i'm unsure of how i should set up a one to many mapping towards the sm_coords table..

as of now i have defined the following table:

self::$prop_tables['smw_polygon'] = new SMWSQLStore2Table(
array( 'coordinate_id' => 'p'),
array( 'coordinate_id' )

where coordinate_id is supposed to refer to sm_coords table entries. however, it seems that no other table here has this type of structure/mapping. So i'm guessing this is the wrong way to go? I could always just have all the data in a clob field instead, but this i'm guessing isn't very optimal when taking semantic search into account.

So how should i create a one to many mapping on the database level as well as on the logic level? or should polygons be stored in some other way?


On Wed, May 23, 2012 at 12:49 PM, Kim Eik <> wrote:
Ok, so i have run into an issue.

A database query syntax error has occurred. This may indicate a bug in the software. The last attempted database query was:
(SQL query hidden)
from within function "SMW::getPropertySubjects". Database returned error "1103: Incorrect table name '' (localhost)".

What i have done so far is defined a new property Geographic polygon. and in my test wiki i tried setting the property [[Has type::Geographical polygon]]

By doing that i'm now getting this database issue. From what i can gather i'm missing a database table to store my structure.
In the existing code i can see tht TYPE_GEO is defined as smw_coords which im guessing is the table name that stores Geographic coordinates.

SMWDataItem::TYPE_GEO        => 'smw_coords', // currently created only if Semantic Maps are installed

Now, how should i proceed to add a table for a polygon?
a polygon is just a collection of coords, so i guess i could use smw_coords as my main table for storing the coordinates of polygons, and then another table that refers to smw_coords with a one to many mapping.

And where in the semantic maps extension can i actually find som sql code that creates the given table?

Oh, and btw, i could use some code review as im piecing this together. would it be ok if i added the code ive written so far to gerrit? so you guys can follow my progress line by line? that way you could probably help me better if other issues arise. So far i have written code for SemanticMediaWiki and SemanticMaps.


On Wed, May 23, 2012 at 11:11 AM, Markus Krötzsch <> wrote:
On 23/05/12 09:02, Kim Eik wrote:
 >From your descritpion, a container data item looks like the way to go
for storing my structures. Do you have a practical example on how
container data item is used?

 From the code documentation i can see that:

 * Being a mere placeholder/template for other data, an SMWDIContainer
is not
 * immutable as the other basic data items. New property-value pairs
can always
 * be added to the internal SMWContainerSemanticData.

so is it correct to assume that in a practical example, in order to
create a container data item, you actually create a template which holds
all your other properties (like a set of [[Polygon::...]] properties)?

The word "template" is not well chosen in this documentation. It has nothing to do with a MW template. When using containers to store data, they are simply like an "internal wiki page" together with property-value assignments. Instead of using containers, one could also create a new wiki page, assign all the data to that wiki page, and then use the wiki page instead of the Container DI as a property value. But this would not fit into one property assignment and would require multiple operations instead. Containers are mainly a convenience structure so that data for multiple (sub)wikipages can be processed in one go.

The word "template" comes in when you use a container value as a search pattern (in queries or in special pages). Then a container can be used without a subject ("anonymous" subject): in this case the subject's name does not matter in the search and only the property values of the container are used to find matches. This is what is meant by "template" in this sentence.

You can see a short code example on how to create arbitrary container DIs in the file SMW_Subobject.php (the implementation of the subobject parser function). This code uses a user-provided name for the subobject. There is also code in SMW_DV_Record.php that generates an internal name on the fly by hashing the data (around line 42). Generated names should start with "_". This allows SMW to decide if a subobject name should be displayed to users or not.

As i said, i'm quite new to this semantic way of structuring data, so
please forgive me for not having a better understanding of how all this
is connected.

And another thing, in which end would you say i should start trying to
implement my data structure, should i start with the individual
dataitems/datavalues and then look at creating a container? do i even
need to create/subclass my own container? or can i use the one already

You can use the one that is already defined. In order to store data in a container, you need properties. You need to register these properties so that they are available (and have the correct type) without the user having to create pages for them. Every property has an internal string ID that you use in the code to address it. It can also have a user-label that users can write to address it (if no label is given, then users will never see it and cannot search for it).

Property registration is done in a hook, for example:

$wgHooks['smwInitProperties'][] = 'myinitProperties';

function myinitProperties() {
 // Register a user-visible property with ID '___myp':
 SMWDIProperty::registerProperty('___myp', '_num', 'Myproperty', true);
 // Register an alternative user label for this property:
 SMWDIProperty::registerPropertyAlias('___myp', 'My property');

 return true;

See the documentation for registerProperty() for details. Always call your own property IDs with three initial underscores to avoid name clashes.

After you registeed properties in this way, you can use them for storing and retrieving values in the container (if they have a user label, you can also use them in the wiki; a good way to try if it worked). In PHP, you can create a property object like this:

$myProperty = new SMWDIProperty('___myp');

Do not use your label but the property ID here. To create a property from its label, you could use the method SMWDIProperty::newFromUserLabel(), but this should not be needed. If the property is registered, SMW will use the right datatype for storing and retrieving it. If the datatype is changed later on, SMW will not find old stored values any more (as expected; if you store values as a string, you don't get them when looking for numbers later on). However, the problem repairs itself over time (old values get deleted when pages are stored again).

Moreover, you can add any value for any property in a Container -- it is not checked if the types are the same (e.g., you can assign a DIString object to a property that is declared to hold a number). If types are not the same, the data might simply not be stored, or might be stored in the wrong place and not be found again. Again, this will repair itself when correcting the code and not cause permanent problems.

One way to inspect the current database contents is Special:Browse (if your properties have user labels). To view properties that have no user label, you can try Special:RDFExport (but this does not have good support for showing data of subobjects).

That's all! It is a lot of material in the beginning, but it is not that complicated in the end ... I hope ;-).