| author | ymh <ymh.work@gmail.com> |
| Thu, 01 Mar 2012 18:44:24 +0100 | |
| changeset 81 | 145296a918f8 |
| parent 68 | e7384fb35f7a |
| child 87 | 499d7998d6ad |
| permissions | -rw-r--r-- |
| 55 | 1 |
|
2 |
# WikiTagBundle |
|
3 |
||
4 |
WikiTagBundle is a php bundle for [Symfony 2](http://symfony.com/) released by the [Institute for research and innovation](http://www.iri.centrepompidou.fr/) (IRI). |
|
5 |
It enables to add semantised tags to any kind of document. |
|
6 |
By semantised, we mean that a tag has its label, but also a wikipedia link related to this label. Right now, for v1.0, it works with the french wikipedia. |
|
7 |
For a simple example, the tag "Asie" is related to the link [http://fr.wikipedia.org/wiki/Asie](http://fr.wikipedia.org/wiki/Asie). |
|
8 |
The tag can also be categorised, by any value in a list. |
|
9 |
The tag can also have an alias, which is any string value. |
|
10 |
When a wikipedia entry is found, the bundle also searches a [dbPedia](http://dbpedia.org/) entry for the english equivalent, for example [http://dbpedia.org/page/Asia](http://dbpedia.org/page/Asia). |
|
11 |
||
12 |
A tag can have 4 kinds of wikipedia links : |
|
13 |
||
14 |
* **match** - Perfect match between the label and the wikipedia entry (i.e. [Asie](http://fr.wikipedia.org/wiki/Asie)). |
|
15 |
* **redirection** - The label exists in wikipedia but redirects to an other entry (i.e. Louis XIV to [Louis XIV de France](http://fr.wikipedia.org/wiki/Louis_XIV_de_France)). |
|
16 |
* **homonymy** - The label leads to wikipedia homonymy page (i.e. [Abstraction](http://fr.wikipedia.org/wiki/Abstraction)). |
|
17 |
* **null result** - The label is not related to any wikipedia entry. So we build a link leading to the search page (i.e. [art multimédia](http://fr.wikipedia.org/w/index.php?search=art+multim%C3%A9dia)). |
|
18 |
||
19 |
||
20 |
||
21 |
## Install |
|
22 |
WikiTagBundle is a php bundle for [Symfony 2](http://symfony.com/). |
|
23 |
||
24 |
* Install the dependencies : [PagerFanta](https://github.com/whiteoctober/Pagerfanta) and [Mondator](https://github.com/mandango/mondator). |
|
25 |
* Download the zipfile from the [downloads](https://github.com/) page and install it. |
|
26 |
* Once unzipped, just copy the IRI folder in your vendor/bundles folder. The folder hierarchy will be vendor/bundles/IRI/Bundle/WikiTagBundle. |
|
27 |
||
28 |
## Getting Started |
|
29 |
* Install WikiTagBundle |
|
30 |
* Register the bundle in AppKernel.php : |
|
31 |
||
32 |
... new IRI\Bundle\WikiTagBundle\WikiTagBundle(), ... |
|
33 |
||
34 |
* Register the namespace in the autoload.php : |
|
35 |
||
36 |
... 'IRI\Bundle\WikiTagBundle' => \_\_DIR\_\_.'/../vendor/bundles', ... |
|
37 |
|
|
38 |
* Register the namespace fallbacks in the autoload.php : |
|
39 |
||
40 |
$loader->registerNamespaceFallbacks(array( |
|
41 |
\_\_DIR\_\_.'/../src', |
|
42 |
\_\_DIR\_\_.'/cache/dev/wikitag', |
|
43 |
\_\_DIR\_\_.'/cache/prod/wikitag', |
|
44 |
\_\_DIR\_\_.'/cache/test/wikitag', |
|
45 |
\_\_DIR\_\_.'/cache/task/wikitag', |
|
46 |
)); |
|
47 |
||
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
48 |
* Since WikiTagBundle builds its own document class from the host app's document class, you need to tell in config.yml what is the host app's document class and what _text_ fields will be used in this class. |
| 55 | 49 |
These fields are used for searching and to calculate the tag's weight. Example : |
50 |
||
51 |
wiki_tag: |
|
52 |
document_class: Company\BaseBundle\Entity\Document |
|
53 |
document_id_column: id |
|
54 |
fields: |
|
55 |
title: |
|
56 |
type: string |
|
57 |
length: 1024 |
|
58 |
accessor: getTitre |
|
59 |
weight: 1.0 |
|
60 |
description: |
|
61 |
type: text |
|
62 |
weight: 0.5 |
|
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
63 |
The 'document_id_column' option is used to indicate the primary key column used by the host app's document class. We are currently limited to non composite primary keys. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
64 |
A field definition has the following format: |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
65 |
<field name>: |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
66 |
type: <string or text> : field type. default : text |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
67 |
length: <int> : the length of the field. ignored if field type is text |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
68 |
accessor: <field name or method name> : the field name in the host app's document class, or the name of the method used to access the field value. If not found it will try ta add 'get' in frint of the name. Default : the field name |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
69 |
weight: <float> : the weight used for this field to calculate the score of each tag. default : 1.0 |
| 55 | 70 |
|
71 |
* Add the WikiTag routes to your routing.yml : |
|
72 |
||
73 |
WikiTagBundle: |
|
74 |
resource: "@WikiTagBundle/Resources/config/routing.yml" |
|
75 |
prefix: /tag |
|
76 |
||
77 |
* Run the commands : |
|
78 |
||
79 |
php app/console wikitag:generate-document-class (no need to explain) |
|
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
80 |
php app/console wikitag:schema:update (also replace and runs php app/console doctrine:schema:update) |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
81 |
php app/console wikitag:sync-doc (fills the database with the datas from the host document class to the wikitag document class. this command is needed only if the database was not empty) |
| 55 | 82 |
|
83 |
* Your database is ready. You can now include the table of tags in a template. Do not forget css and javascript (and php app/console assets:install). Example : |
|
84 |
||
85 |
{# example of page extending the base template #} |
|
86 |
{% extends 'CompanyBaseBundle:Default:index.html.twig' %} |
|
87 |
||
88 |
{% block css_import %} |
|
89 |
{{ parent() }} |
|
90 |
{% render "WikiTagBundle:WikiTag:addCss" %} |
|
91 |
{% endblock %} |
|
92 |
||
93 |
{% block js_declaration %} |
|
94 |
{{ parent() }} |
|
95 |
{% render "WikiTagBundle:WikiTag:addJavascript" %} |
|
96 |
{% endblock %} |
|
97 |
||
98 |
{% block content %} |
|
99 |
<!-- The beginning of your template --> |
|
100 |
{% render "WikiTagBundle:WikiTag:documentTags" with {'id_doc': doc.id} %} |
|
101 |
<!-- The end of your template --> |
|
102 |
{% endblock %} |
|
103 |
|
|
104 |
* Great ! You can now add/remove/change semantised tags to your document ! The WikiTag template includes an autocomplete search field to add simply and fastly any wikipedia semantised tag. |
|
105 |
||
106 |
||
107 |
## The list of all tags |
|
108 |
If you want to, you can add into a page the list of all tags. WikiTagBundle manages a list of all tags with the paginator PagerFanta. By default, it displays 50 tags per page. |
|
109 |
The template includes links to quick search via a list of tags's first letter. A search field is also included. It works with the star character (\*) as a delimiter for searching. |
|
110 |
For example "\*Peter" will return tags ending by Peter, "Peter\*" tags beginning by Peter, and "\*Peter\*" all tags including Peter. |
|
111 |
The list can be sorted in ascending or descending label, number of documents or popularity (integer value). |
|
112 |
WikiTagBundle manages pagination, search, and sort with url parameters. |
|
113 |
||
114 |
Example : http://mysite.com/route\_to\_list?searched=Peter\*&num\_page=1&nb\_by\_page=50&sort=popd |
|
115 |
||
116 |
Including the tag list template looks like : |
|
117 |
||
118 |
{# example of template including the all tags list #} |
|
119 |
{% extends 'CompanyBaseBundle:Default:index.html.twig' %} |
|
120 |
||
121 |
{% block css_import %} |
|
122 |
{{ parent() }} |
|
123 |
{% render "WikiTagBundle:WikiTag:addCss" %} |
|
124 |
{% endblock %} |
|
125 |
||
126 |
{% block js_declaration %} |
|
127 |
{{ parent() }} |
|
128 |
{% render "WikiTagBundle:WikiTag:addJavascript" with {'tags_list': true} %} |
|
129 |
{% endblock %} |
|
130 |
||
131 |
{% block content %} |
|
132 |
<!-- The beginning of your template --> |
|
133 |
{% render "WikiTagBundle:WikiTag:allTags" %} |
|
134 |
<!-- The end of your template --> |
|
135 |
{% endblock %} |
|
136 |
||
137 |
*IMPORTANT* : This template needs a route to be defined in configuration file. Usually, this host site's route leads the a page/document concerned by the clicked tag. |
|
138 |
This route is used by the list to create a link on the "nb of documents" column. config.yml looks like : |
|
139 |
||
140 |
wiki_tag: |
|
141 |
route_for_documents_by_tag: a_route_from_host_site |
|
142 |
document_class: Company\BaseBundle\Entity\Document |
|
143 |
... |
|
144 |
||
145 |
||
146 |
## More configuration 1 : tag list profile for a document |
|
147 |
Via config.yml, you can configure which columns are displayed by default for a given user. It also concerns the button "sort tags" |
|
148 |
(This function orders tags depending of their presence in the text fields set in config.yml). |
|
149 |
Is it is very simple, you define the list of columns the user profile will see by default. In the following example, the list values are the ones to use : |
|
150 |
||
151 |
wiki_tag: |
|
152 |
... |
|
153 |
document_list_profile: |
|
154 |
all: [ 'sort_tag', 'order', 'id', 'move_up_down', 'label', 'wikipedia_link', 'wikipedia_permalink', 'dbpedia_link', 'category', 'remove_wikipedia_link', 'alias', 'remove_tag_from_list', 'alternative_label', 'alternative_wikipedia_url' ] |
|
155 |
editor : [ 'order', 'id', 'move_up_down', 'label', 'wikipedia_link', 'wikipedia_permalink', 'dbpedia_link', 'category', 'remove_wikipedia_link', 'remove_tag_from_list' ] |
|
156 |
contributor: [ 'sort_tag', 'order', 'label', 'wikipedia_link', 'wikipedia_permalink', 'delete_wikipedia_link', 'remove_tag_from_list' ] |
|
157 |
||
158 |
In these values, "sort_tag" means the sort tag button. All the other values are the available columns in the tag table. |
|
159 |
Once this configuration set, call the profile in your template. The profile has to be called in the javascript call AND in the html call. So your template will look like this : |
|
160 |
||
161 |
... |
|
162 |
{% render "WikiTagBundle:WikiTag:addJavascript" with {'profile_name': 'editor'} %} |
|
163 |
... |
|
164 |
{% render "WikiTagBundle:WikiTag:documentTags" with {'id_doc': doc.id, 'profile_name': 'editor'} %} |
|
165 |
... |
|
166 |
||
167 |
||
168 |
## More configuration 2 : add context seach to any text part of your page |
|
169 |
Via config.yml, you can configure a list of jquery selectors meant to let appear tag context search by selecting text. |
|
170 |
Once some text selected, a little div appears and displays several wikipedia entries with the entry title and a snippet. The results are the same than in an opensearch page |
|
171 |
(example with [découvrir](http://fr.wikipedia.org/w/index.php?search=d%C3%A9couvrir)). If you want this functionality, config.yml will look like this : |
|
172 |
||
173 |
wiki_tag: |
|
174 |
... |
|
175 |
reactive_selectors: |
|
176 |
some_divs: [ '.left_sheet', '#p_title .sheet_title', '#p_description' ] |
|
177 |
only_p: [ '#p_title .sheet_title', '#p_description' ] |
|
178 |
whole_page: [ 'document' ] |
|
179 |
||
180 |
If you want every text on your page to be reactive, the list has to be [ 'document' ]. |
|
181 |
In the templates, you have to call a specific javascript with the wanted parameter. Your javascript calls may look like this : |
|
182 |
||
183 |
{% block js_declaration %} |
|
184 |
{{ parent() }} |
|
185 |
{% render "WikiTagBundle:WikiTag:addJavascript" with {'profile_name': 'editor'} %} |
|
186 |
{% render "WikiTagBundle:WikiTag:addJavascriptForContextSearch" with {'context_name': 'some_divs'} %} |
|
187 |
{% endblock %} |
|
188 |
||
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
189 |
## More configuration 3 : ignore wikipedia errors |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
190 |
This option allows to ignore wikipedia errors instead of raising an exception. The error is logged with an ERROR level and the tag is added/updated but not semantized. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
191 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
192 |
wiki_tag: |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
193 |
... |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
194 |
ignore_wikipedia_error: true |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
195 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
196 |
## Services |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
197 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
198 |
### Document Service : wiki_tag.document - IRI\Bundle\WikiTagBundle\Services\DocumentService |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
199 |
The document service gathers methods to manage tags on a given document. all these methods must be called after the host app's document(s) object has been created and flushed. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
200 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
201 |
* addTags : add a tag or a list pf tags to a document. For each new tag, wikipedia will be queried. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
202 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
203 |
* copyTags : copy the tags list from one document to the other. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
204 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
205 |
* reorderTags : reorder a document tags. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
206 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
207 |
* getTagsLabels : get the list of tag labels from one document. |
| 55 | 208 |
|
209 |
||
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
210 |
### Search service : wiki_tag.search - IRI\Bundle\WikiTagBundle\Services\SearchService |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
211 |
The search service allows searching documents |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
212 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
213 |
* getTagCloud : returns a weighted list of tag labels. The weight of the label is the number of documents tagged with this label. The list is sorted by descending weights. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
214 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
215 |
* search : search documents. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
216 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
217 |
## Commands |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
218 |
This bundle provides a number of commans that helps in the tags management. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
219 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
220 |
### wikitag:schema:create |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
221 |
Command to create the database schema. Equivalent to the doctrine:schema:create command. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
222 |
It fully replaces the doctrine:schema:create and *must* be run instead of the doctrine:schema:create command. |
| 55 | 223 |
|
224 |
||
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
225 |
### wikitag:schema:update |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
226 |
Command to update the database schema. Equivalent to the doctrine:schema:update command. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
227 |
It fully replaces the doctrine:schema:update and *must* be run instead of the doctrine:schema:update command. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
228 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
229 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
230 |
### wikitag:create-fulltext-indexes |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
231 |
Generate the sql to create the full text index on the database. This command is not destined to be directly called. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
232 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
233 |
### wikitag:generate-document-class |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
234 |
Generate the WikiTagBundle document class. This command should not be directly called. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
235 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
236 |
### wikitag:purge-tags |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
237 |
Removes tags associated to no documents. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
238 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
239 |
### wikitag:query-wikipedia |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
240 |
Query wikipedia for informations on tags. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
241 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
242 |
### wikitag:reorder-tags |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
243 |
Automatically reorder documents tags. For each documents treated, each tag of the document is scored according to the fields definition in the bundle configuration. The sorting of the tags is done document by document according to these scores. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
244 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
245 |
### wikitag:sync-doc |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
246 |
Synchronize the wikiTag Bundle documents with the host bundle. This synchronization is made according to the fields defined in the bundle configuration. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
55
diff
changeset
|
247 |