tcf2nif 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f244b1143fade6e88fec59ad9adfe89d6f78da75
4
+ data.tar.gz: 25e7e33477ae1cfded5ffad85b56d6c6e511eaca
5
+ SHA512:
6
+ metadata.gz: ba6d13d4d65d6fc591940a549c8d69ba03ea2036d5346c0c36cce13e7b72427e142f15e55055192107e1ccba4e1cd2e6071f83c1778f9805e901a2a2458c9da0
7
+ data.tar.gz: 9e07c4317a514f6283e5983352e86585cb290bd520a6c9a22dd4fbb5246d370e5946ccb0355aee0282810db2a8e0e6f206308f5b70e601c9b6cdd3a4ba702809
@@ -0,0 +1,37 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
11
+ spec/out/*.ttl
12
+ spec/out/*.nt
13
+ spec/out/plainprov/*.ttl
14
+ spec/out/tcf2nif
15
+ spec/coverage
16
+ spec/out/miserables.n3
17
+ spec/out/phantom.n3
18
+ spec/out/screw.n3
19
+ spec/logs/misplain.log
20
+ spec/logs/phanplain.log
21
+ spec/logs/screwplain.log
22
+ spec/out/plainprov/miserables.nt
23
+ spec/out/plainprov/phantom.nt
24
+ spec/out/plainprov/phantom.ttl
25
+ spec/out/plainprov/screw.nt
26
+
27
+ /.ipynb_checkpoints/
28
+ spec/out/*.*
29
+ jack.*
30
+ newchain.xml
31
+ testchain.xml
32
+ screw.xml
33
+ otherchain.xml
34
+ token.txt
35
+ spec/out/modularized/phantom.n3
36
+ spec/out/modularized/phantom.ttl
37
+ spec/out/modularized/tools.ttl
@@ -0,0 +1,25 @@
1
+ before_script:
2
+ - echo off
3
+ - source /etc/profile.d/rvm.sh
4
+ - rvm use 2.2@mine
5
+ - echo on
6
+ #- gem install bundler
7
+ - bundle install
8
+ #- bundle exec rake db:create
9
+
10
+ rspec:
11
+ script: "rake spec"
12
+ tags:
13
+ - ~slow
14
+ only:
15
+ - branches
16
+
17
+ #staging:
18
+ # script: "cap deploy stating"
19
+ # type: deploy
20
+ # tags:
21
+ # - capistrano
22
+ # - debian
23
+ # except:
24
+ # - stable
25
+ # - /^deploy-.*$/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tcf2nif.gemspec
4
+ gemspec
5
+
6
+ gem 'iruby'
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,112 @@
1
+ # tcf2nif
2
+
3
+ ![Gitlab CI Information](http://ci.streusel.org/projects/1/status.png?ref=master)
4
+
5
+ `tcf2nif` is a NLP data converter from the TCF format (used by WebLicht) to the RDF-based NIF format. At the moment, it has a limited functionality.
6
+
7
+ ## License
8
+
9
+ tcf2nif is released under the GNU Lesser General Public License (version 3). See `LICENSE.txt` for details.
10
+
11
+
12
+ ## Version History
13
+
14
+ ### 0.2.1 - tiny correction for making CI succeed again (30 Oct 2015)
15
+
16
+ - support for a new test output directory was added, now CI succeeds again
17
+
18
+ ### 0.2.0 - First working exe scripts (30 Oct 2015)
19
+
20
+ - Adds first versions of the executable scripts for doc conversions
21
+
22
+ - __txt2tcf__ (converts plain text to TCF, using WebLicht)
23
+ - __tcf2nif__ (converts TCF/WebLicht documents to NIF)
24
+
25
+ ### 0.1.0 - Initial prototype (22 Sep 2015)
26
+
27
+ - This is the proof of concept version with minimal functionality
28
+
29
+ ## Installation
30
+
31
+ Add this line to your application's Gemfile:
32
+
33
+ ```ruby
34
+ gem 'tcf2nif'
35
+ ```
36
+
37
+ And then execute:
38
+
39
+ $ bundle
40
+
41
+ Or install it yourself as:
42
+
43
+ $ gem install tcf2nif
44
+
45
+ ## Usage
46
+
47
+ See the [Jupyter notebook][notebook] for a hands-on experience and code examples.
48
+
49
+ This gem provides a proof of concept for reading TCF data (the file format used by [the WebLicht services][weblicht]).
50
+
51
+ ### Reading TCF documents
52
+
53
+ In a nutshell, an instance of a TcfDocument can be obtained from any `IO` object that contains a representation of a TCF XML stream:
54
+
55
+ ``` Ruby
56
+ @tcf_document = Tcf2Nif::TcfDocument.new(@io)
57
+ ```
58
+
59
+ where `@io` is a Ruby IO object (a file, a stream, etc.). This TCF document can then be queried in different ways:
60
+
61
+ ``` Ruby
62
+ # get the primary text
63
+ puts @tcf_document.text
64
+ # get an enumeration of Tcf2Nif::Token instances.
65
+ # these tokens contain the word form,
66
+ # and, if the respective services have been performed,
67
+ # also some annotations.
68
+ @tcf_document.tokens.each do |token|
69
+ # do something clever with the tokens
70
+ puts token.form
71
+ puts token.pos? # true iff pos annotation is present
72
+ puts token.lemma? # true iff lemma annotation is present
73
+ puts token.pos # returns the pos annotation
74
+ puts token.lemma # returns the lemma annotation
75
+ end
76
+ # Depending on what is present in the TCF file,
77
+ # you can also access some other levels of annotations:
78
+ @tcf_document.geo_annotations
79
+ @tcf_document.dependency_map
80
+ ```
81
+
82
+ ### Conversion to NIF
83
+
84
+ The `Tcf2Nif::Transformer` class provides instances that can convert from a TCF document to an RDF graph containing NIF.
85
+
86
+ ``` Ruby
87
+ @transformer = Tcf2Nif::Transformer.new(@tcf_doc, {})
88
+ graph = @trans.transform() # creates an instance of RDF::Graph
89
+ puts graph.size
90
+ RDF::Writer.open('path/to/outputfile'), :format => :ntriples) do |writer|
91
+ writer << RDF::Repository.new do |repo|
92
+ repo << graph
93
+ end
94
+ end
95
+ ```
96
+
97
+ ## Development
98
+
99
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec tcf2nif` to use the code located in this directory, ignoring other installed copies of this gem.
100
+
101
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
102
+
103
+ ## Contributing
104
+
105
+ 1. Fork it ( https://github.com/[my-github-username]/tcf2nif/fork )
106
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
107
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
108
+ 4. Push to the branch (`git push origin my-new-feature`)
109
+ 5. Create a new Pull Request
110
+
111
+ [notebook]: ./Tcf2Nif.ipynb "The Tcf2Nif Jupyter Notebook"
112
+ [weblicht]: http://weblicht.sfs.uni-tuebingen.de/weblichtwiki/index.php/Main_Page
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,197 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# Comparison of the different conversion routines\n",
8
+ "\n",
9
+ "First, import the relevant stuff."
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": 5,
15
+ "metadata": {
16
+ "collapsed": false,
17
+ "scrolled": false
18
+ },
19
+ "outputs": [
20
+ {
21
+ "data": {
22
+ "text/plain": [
23
+ "Object"
24
+ ]
25
+ },
26
+ "execution_count": 5,
27
+ "metadata": {},
28
+ "output_type": "execute_result"
29
+ }
30
+ ],
31
+ "source": [
32
+ "require 'rspec'\n",
33
+ "require 'tcf2nif'\n",
34
+ "include Tcf2Nif"
35
+ ]
36
+ },
37
+ {
38
+ "cell_type": "markdown",
39
+ "metadata": {
40
+ "collapsed": true
41
+ },
42
+ "source": [
43
+ "## Vanilla NIF approach\n",
44
+ "\n",
45
+ "Then create our sample documents and a transformer object. "
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "execution_count": 6,
51
+ "metadata": {
52
+ "collapsed": false
53
+ },
54
+ "outputs": [],
55
+ "source": [
56
+ "@testfile = File.open(File.join('.', 'spec', 'assets', 'phantom.xml'), 'r')\n",
57
+ "@tcf_doc = TcfDocument.new(@testfile)\n",
58
+ "@trans = Transformer.new(@tcf_doc, {})"
59
+ ]
60
+ },
61
+ {
62
+ "cell_type": "markdown",
63
+ "metadata": {},
64
+ "source": [
65
+ "Now, for the vanilla approach, we do a basic conversion."
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "execution_count": null,
71
+ "metadata": {
72
+ "collapsed": false
73
+ },
74
+ "outputs": [],
75
+ "source": [
76
+ "graph = @trans.transform(:noprov)\n",
77
+ "puts graph.size"
78
+ ]
79
+ },
80
+ {
81
+ "cell_type": "markdown",
82
+ "metadata": {},
83
+ "source": [
84
+ "We can also run the `noprov` RSpec tasks. "
85
+ ]
86
+ },
87
+ {
88
+ "cell_type": "code",
89
+ "execution_count": null,
90
+ "metadata": {
91
+ "collapsed": false
92
+ },
93
+ "outputs": [],
94
+ "source": [
95
+ "RSpec.configure do |config|\n",
96
+ " config.filter_run_including :noprov => true\n",
97
+ " config.run_all_when_everything_filtered = true\n",
98
+ "end\n",
99
+ "RSpec::Core::Runner::run(['spec'])"
100
+ ]
101
+ },
102
+ {
103
+ "cell_type": "markdown",
104
+ "metadata": {},
105
+ "source": [
106
+ "## Plain NIF approach\n",
107
+ "\n",
108
+ "This approach reifies some of the RDF in order to make annotations identifiable. "
109
+ ]
110
+ },
111
+ {
112
+ "cell_type": "markdown",
113
+ "metadata": {},
114
+ "source": [
115
+ "Finally, read TCF, transform to NIF, and show us the number of triples."
116
+ ]
117
+ },
118
+ {
119
+ "cell_type": "code",
120
+ "execution_count": null,
121
+ "metadata": {
122
+ "collapsed": false
123
+ },
124
+ "outputs": [],
125
+ "source": []
126
+ },
127
+ {
128
+ "cell_type": "code",
129
+ "execution_count": null,
130
+ "metadata": {
131
+ "collapsed": true
132
+ },
133
+ "outputs": [],
134
+ "source": []
135
+ },
136
+ {
137
+ "cell_type": "markdown",
138
+ "metadata": {},
139
+ "source": [
140
+ "## Pos Tagger Comparison\n",
141
+ "\n",
142
+ "This section contains SPARQL stuff for comparing POS taggers. With plain NIF, a query could be something like this:"
143
+ ]
144
+ },
145
+ {
146
+ "cell_type": "markdown",
147
+ "metadata": {},
148
+ "source": [
149
+ "```SPARQL\n",
150
+ "prefix xsd: <http://www.w3.org/2001/XMLSchema#>\n",
151
+ "prefix skos: <http://www.w3.org/2004/02/skos/core#>\n",
152
+ "prefix owl: <http://www.w3.org/2002/07/owl#>\n",
153
+ "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
154
+ "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n",
155
+ "prefix nif: <http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#>\n",
156
+ "prefix penn: <http://purl.org/olia/penn.owl#>\n",
157
+ "prefix ex: <http://example.org/tcf2nif/example.txt#>\n",
158
+ "\n",
159
+ "SELECT ?begin ?end ?anchor ?pos WHERE {\n",
160
+ " ?nif\n",
161
+ " nif:beginIndex ?begin ;\n",
162
+ " nif:endIndex ?end ;\n",
163
+ " nif:beginIndex \"4991\"^^xsd:nonNegativeInteger ;\n",
164
+ " nif:anchorOf ?anchor ;\n",
165
+ " nif:oliaLink ?pos .\n",
166
+ "}\n",
167
+ "```"
168
+ ]
169
+ },
170
+ {
171
+ "cell_type": "markdown",
172
+ "metadata": {},
173
+ "source": [
174
+ "results in two answers:\n",
175
+ "\n",
176
+ "- 4991, 4996, judge, <http://purl.org/olia/penn.owl#NN>\n",
177
+ "- 4991, 4996, judge, <http://purl.org/olia/penn.owl#VB>"
178
+ ]
179
+ }
180
+ ],
181
+ "metadata": {
182
+ "celltoolbar": "Raw Cell Format",
183
+ "kernelspec": {
184
+ "display_name": "Ruby 2.2.1",
185
+ "language": "ruby",
186
+ "name": "ruby"
187
+ },
188
+ "language_info": {
189
+ "file_extension": "rb",
190
+ "mimetype": "application/x-ruby",
191
+ "name": "ruby",
192
+ "version": "2.2.1"
193
+ }
194
+ },
195
+ "nbformat": 4,
196
+ "nbformat_minor": 0
197
+ }