Archive:Development/Tutorials/Metadata/Nepomuk/ResourceGenerator (zh CN)
Development/Tutorials/Metadata/Nepomuk/ResourceGenerator
Languages: عربي | Asturianu | Català | Česky | Kaszëbsczi | Dansk | Deutsch | English | Esperanto | Español | Eesti | فارسی | Suomi | Français | Galego | Italiano | 日本語 | 한국어 | Norwegian | Polski | Português Brasileiro | Română | Русский | Svenska | Slovenčina | Slovenščina | српски | Türkçe | Tiếng Việt | Українська | 简体中文 | 繁體中文
Tutorial Series | [[../|Nepomuk]] |
Previous | [[../RDFIntroduction|RDF和本体简介]] |
What's Next | [[../AdvancedQueries|Nepomuk高级查询]] |
Further Reading | [[../Resources|Resource Handling with Nepomuk]], Nepomuk资源类产生器 (KDE API Dox) |
请参见Nepomuk资源产生.
Development/Tutorials/Metadata/Nepomuk/ResourceGenerator
Languages: عربي | Asturianu | Català | Česky | Kaszëbsczi | Dansk | Deutsch | English | Esperanto | Español | Eesti | فارسی | Suomi | Français | Galego | Italiano | 日本語 | 한국어 | Norwegian | Polski | Português Brasileiro | Română | Русский | Svenska | Slovenčina | Slovenščina | српски | Türkçe | Tiếng Việt | Українська | 简体中文 | 繁體中文
Nepomuk资源类产生器
Nepomuk::Resource提供了一个办法,可以用QUrl对象来辨识属性以及辨识Nepomuk::Variant,同时还提供读写功能。但这不是个太好的办法,开发人员要在代码里写死属性URL,要么用Soprano's onto2vocabularyclass工具来生成词汇(Vocabulary)的名字空间。
最简单的办法就是用资源产生器来生成包装类,用包装类来读写各个属性。properties.
这里的想法就是:每个RDF类都对应一个Nepomuk::Resource子类,以他来对RDF类的各个领域属性提供存取方法。
使用CMake
Nepomuk提供了CMake的宏定义,可以用它来使用资源生成器。KDE 4.4已经定义了nepomuk_add_ontology_classes的宏。对KDE 4.3,我们还的用playground的macro_add_ontology_classes宏.
语法很简单,和添加一系列资源文件的宏定义差不多:
NEPOMUK_ADD_ONTOLOGY_CLASSES(<sources-var>
[FAST]
[ONTOLOGIES] <onto-file1> [<onto-file2> ...]
[CLASSES <classname1> [<classname2> ...]]
[VISIBILITY <visibility-name>]
)
If FAST is specified the rcgen parameter --fast will be used which results in resource classes not based on Nepomuk::Resource but on a custom class which does not perform any checks and simply writes the data to Nepomuk (hence the name fast).
The optional CLASSES parameter allows to specify the classes to be generated (RDF class names) in case one does not want all classes in the ontologies to be generated. If omitted all classes in the ontology files will be generated.
The optional VISIBILITY parameter can only be used in non-fast mode and allows to set the gcc visibility to make the generated classes usable in a publically exported API. The <visibility-name> is used to create the name of the export macro and the export include file. Thus, when using "VISIBILITY foobar" include file "foobar_export.h" needs to define FOOBAR_EXPORT.
案例
include(NepomukAddOntologyClasses)
set(SRCS [...])
nepomuk_add_ontology_classes(SRCS ONTOLOGIES ontology.trig)
kde4_add_executable(foobar ${SRCS})
target_link_libraries(foobar
nepomuk
)