Archive:Development/Tutorials/Metadata/Nepomuk/ResourceGenerator (zh CN): Difference between revisions

From KDE TechBase
(New page: {{Template:I18n/Language Navigation Bar|Development/Tutorials/Metadata/Nepomuk/ResourceGenerator}} {{TutorialBrowser| series=[[../|Nepomuk]]| name=使用Nepomuk资源产生器| pre=[[../R...)
 
(i18n)
Line 3: Line 3:
{{TutorialBrowser|
{{TutorialBrowser|
series=[[../|Nepomuk]]|
series=[[../|Nepomuk]]|
name=使用Nepomuk资源产生器|
name=使用Nepomuk资源类产生器|
pre=[[../RDFIntroduction|介绍RDF和本体]]|
pre=[[../RDFIntroduction|RDF和本体简介]]|
next=|
next=[[../AdvancedQueries|Nepomuk高级查询]]|
reading=[[../Resources|用Nepomuk处理资源]], [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/nepomuk-rcgen.html Nepomuk资源产生器]|
reading=[[../Resources|Resource Handling with Nepomuk]], [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/nepomuk-rcgen.html Nepomuk资源类产生器 (KDE API Dox)]|
}}
}}


请参见[http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/nepomuk-rcgen.html Nepomuk资源产生].
请参见[http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/nepomuk-rcgen.html Nepomuk资源产生].
{{Template:I18n/Language Navigation Bar|Development/Tutorials/Metadata/Nepomuk/ResourceGenerator}}
==Nepomuk资源类产生器==
[http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/classNepomuk_1_1Resource.html Nepomuk::Resource]提供了一个办法,可以用QUrl对象来辨识属性以及辨识Nepomuk::Variant,同时还提供读写功能。但这不是个太好的办法,开发人员要在代码里写死属性URL,要么用[http://soprano.sourceforge.net/apidox/stable/soprano_devel_tools.html Soprano's onto2vocabularyclass]工具来生成词汇(Vocabulary)的名字空间。
最简单的办法就是用资源产生器来生成包装类,用包装类来读写各个属性。properties.
这里的想法就是:每个RDF类都对应一个Nepomuk::Resource子类,以他来对RDF类的各个领域属性提供存取方法。
===使用CMake===
Nepomuk提供了CMake的宏定义,可以用它来使用资源生成器。KDE 4.4已经定义了''nepomuk_add_ontology_classes''的宏。对KDE 4.3,我们还的用[http://websvn.kde.org/trunk/playground/base/nepomuk-kde/cmake/modules/MacroAddOntologyClasses.cmake?view=markup playground]的''macro_add_ontology_classes''宏.
语法很简单,和添加一系列资源文件的宏定义差不多:
<code>
NEPOMUK_ADD_ONTOLOGY_CLASSES(<sources-var>
        [FAST]
        [ONTOLOGIES] <onto-file1> [<onto-file2> ...]
        [CLASSES <classname1> [<classname2> ...]]
        [VISIBILITY <visibility-name>]
      )
</code>
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.
====案例====
<code>
include(NepomukAddOntologyClasses)
set(SRCS [...])
nepomuk_add_ontology_classes(SRCS ONTOLOGIES ontology.trig)
kde4_add_executable(foobar ${SRCS})
target_link_libraries(foobar
  nepomuk
)
</code>

Revision as of 06:02, 7 September 2009


Development/Tutorials/Metadata/Nepomuk/ResourceGenerator


使用Nepomuk资源类产生器
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


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,我们还的用playgroundmacro_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

)