Class: When::Events::Event
- Inherits:
-
Object
- Object
- When::Events::Event
- Defined in:
- lib/when_exe/events.rb
Overview
時間座標を持つイベント
Instance Attribute Summary collapse
-
#csv ⇒ Hash<String(番号)=>Object>
readonly
CSV変数.
-
#dataset ⇒ When::Events::DataSet
readonly
所属する一言語対応データセット.
-
#id ⇒ Integer
readonly
通し番号.
-
#order ⇒ Hash<String(prefix:name)=>Array(Integer(id))>
readonly
当該順序キーで何番目のイベントか.
-
#rdf ⇒ Hash<String(prefix:name)=>Object>
readonly
RDF変数.
-
#role ⇒ Hash<String(prefix:name)=>Object>
readonly
ロール変数.
-
#row ⇒ Array<String>
readonly
CSVの一行分.
Instance Method Summary collapse
-
#abstract(item = ABSTRACT, method = :role) ⇒ String
指定の情報を{}部分のマークアップ処理など行って整形して返す.
-
#deep_copy ⇒ When::Events::Event
イベントの複製.
-
#each_word ⇒ Object
HAS_PART対象の文字列中の{}で囲まれた語に対して yield で指定された処理を行う.
-
#group ⇒ String
イベントが属するグループ(@role)を返す.
-
#initialize(dataset, id, row) ⇒ Event
constructor
イベントの生成.
-
#source(item = SOURCE, method = :role) ⇒ Array<String(IRI), String(説明)>
指定の情報のIRIとその説明を返す.
-
#statements ⇒ Array<RDF::Statement>
自身を主語とする RDF::Statement の Array を返す.
Constructor Details
#initialize(dataset, id, row) ⇒ Event
イベントの生成
1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 |
# File 'lib/when_exe/events.rb', line 1783 def initialize(dataset, id, row) @dataset = dataset @id = id @row = row @role = {} @rdf = {} @csv = {} @order = {} case row when Hash @rdf = row when Array row.each_with_index do |item, index| @csv[(index+1).to_s] = item end dataset.rdf.each_pair do |item, definition| fields = [] format = definition[:target].gsub(/\[(\d+)\]/) { field = row[$1.to_i-1] field = escape(field, definition[:type]) fields << field '%s' } @rdf[item] = definition[:operation].call(self, format == '%s' ? fields.first : format % fields) end end @role[ID] = @rdf[ID] = id dataset.role.each_pair do |item, definition| fields = [] format = definition[:target].gsub('%','%%').gsub(/\[(\d+)\]|<(.+?)>|\{(.+?)\}/) {|match| key = $1 || $2 || $3 field = case match when /\A\[/ ; row[key.to_i-1] when /\A</ ; @rdf[key] when /\A\{/ ; @role[key] end field = escape(field, definition[:type]) fields << field '%s' } pre_operation = DataSet::Operations[item] @role[item] = if pre_operation definition[:operation].call(self, pre_operation.call(self, format == '%s' ? fields.first : format % fields)) else definition[:operation].call(self, format == '%s' ? fields.first : format % fields) end end end |
Instance Attribute Details
#csv ⇒ Hash<String(番号)=>Object>
CSV変数
1653 1654 1655 |
# File 'lib/when_exe/events.rb', line 1653 def csv @csv end |
#dataset ⇒ When::Events::DataSet (readonly)
所属する一言語対応データセット
1616 1617 1618 |
# File 'lib/when_exe/events.rb', line 1616 def dataset @dataset end |
#id ⇒ Integer (readonly)
通し番号
1623 1624 1625 |
# File 'lib/when_exe/events.rb', line 1623 def id @id end |
#order ⇒ Hash<String(prefix:name)=>Array(Integer(id))> (readonly)
当該順序キーで何番目のイベントか
1661 1662 1663 |
# File 'lib/when_exe/events.rb', line 1661 def order @order end |
#rdf ⇒ Hash<String(prefix:name)=>Object>
RDF変数
1645 1646 1647 |
# File 'lib/when_exe/events.rb', line 1645 def rdf @rdf end |
#role ⇒ Hash<String(prefix:name)=>Object>
ロール変数
1637 1638 1639 |
# File 'lib/when_exe/events.rb', line 1637 def role @role end |
Instance Method Details
#abstract(item = ABSTRACT, method = :role) ⇒ String
Note:
ブロックを渡された場合、そのブロックに{}部分のマークアップを依頼する
指定の情報を{}部分のマークアップ処理など行って整形して返す
1684 1685 1686 1687 1688 1689 |
# File 'lib/when_exe/events.rb', line 1684 def abstract(item=ABSTRACT, method=:role) send(method)[item].gsub(/(\{+)(.*?)(\}+)/) { bra, word, cket = $~[1..3] '{'*(bra.length/2) + (block_given? ? yield(word) : word) + '}'*(cket.length/2) } end |
#deep_copy ⇒ When::Events::Event
イベントの複製
1767 1768 1769 1770 1771 1772 1773 |
# File 'lib/when_exe/events.rb', line 1767 def deep_copy result = self.dup result.csv = @csv.dup result.rdf = @rdf.dup result.role = @role.dup result end |
#each_word ⇒ Object
HAS_PART対象の文字列中の{}で囲まれた語に対して yield で指定された処理を行う
1666 1667 1668 1669 1670 1671 1672 |
# File 'lib/when_exe/events.rb', line 1666 def each_word @role[HAS_PART].scan(/(\{+)(.*?)(\}+)/) do bra, word, cket = $~[1..3] next unless bra.length.odd? && cket.length.odd? yield(word) end end |
#group ⇒ String
1714 1715 1716 |
# File 'lib/when_exe/events.rb', line 1714 def group @role[GROUP] end |
#source(item = SOURCE, method = :role) ⇒ Array<String(IRI), String(説明)>
指定の情報のIRIとその説明を返す
1699 1700 1701 1702 1703 1704 1705 1706 1707 |
# File 'lib/when_exe/events.rb', line 1699 def source(item=SOURCE, method=:role) iri = send(method)[item] return [nil, iri] unless /:\/\// =~ iri @dataset.prefix_description.each do |description| index = iri.index(description[0]) return [iri, description[1]] if index && index == 0 end [iri] end |
#statements ⇒ Array<RDF::Statement>
自身を主語とする RDF::Statement の Array を返す
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 |
# File 'lib/when_exe/events.rb', line 1723 def statements unless @statements @statements = [] raise ArgumentError, 'Role for rdf:subject not defined' unless @role.key?(SUBJECT) subject = @dataset.resource[@role[SUBJECT]] @role.each_pair do |predicate, object| case predicate when SUBJECT, ID, GRAPH, WHAT_DAY # Do nothing when HAS_PART if @role[HAS_PART].kind_of?(Array) words = @role[HAS_PART] else words = [] each_word do |word| words << word end words.uniq! end words.each do |word| @statements << ::RDF::Statement(subject, @dataset.resource[predicate], word) end # when ABSTRACT # @statements << ::RDF::Statement(subject, @dataset.resource[predicate], abstract) else if [URI, IRI].include?(@dataset.role[predicate][:type]) object = @dataset.resource[object] elsif object.respond_to?(:to_uri) object = object.to_uri elsif @dataset.role[predicate][:lang] != '' && object.kind_of?(String) object = ::RDF::Literal.new(object, {:language=>@dataset.role[predicate][:lang]}) end @statements << ::RDF::Statement(subject, @dataset.resource[predicate], object) end end end @statements end |