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
所属する一言語対応データセット.
-
#date ⇒ When::TM::TemporalPosition or When::Events::Range
readonly
日付または日付範囲.
-
#id ⇒ Integer
readonly
通し番号.
-
#order ⇒ Hash<String(prefix:name)=>Array(Integer(id))>
readonly
当該順序キーで何番目のイベントか.
-
#original ⇒ When::Events::Event
readonly
deep copy 時の元イベント.
-
#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
イベントの生成
1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 |
# File 'lib/when_exe/events.rb', line 1818 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 @date = @role[VALID] end |
Instance Attribute Details
#csv ⇒ Hash<String(番号)=>Object>
CSV変数
1664 1665 1666 |
# File 'lib/when_exe/events.rb', line 1664 def csv @csv end |
#dataset ⇒ When::Events::DataSet (readonly)
所属する一言語対応データセット
1627 1628 1629 |
# File 'lib/when_exe/events.rb', line 1627 def dataset @dataset end |
#date ⇒ When::TM::TemporalPosition or When::Events::Range
日付または日付範囲
1687 1688 1689 |
# File 'lib/when_exe/events.rb', line 1687 def date @date end |
#id ⇒ Integer (readonly)
通し番号
1634 1635 1636 |
# File 'lib/when_exe/events.rb', line 1634 def id @id end |
#order ⇒ Hash<String(prefix:name)=>Array(Integer(id))> (readonly)
当該順序キーで何番目のイベントか
1672 1673 1674 |
# File 'lib/when_exe/events.rb', line 1672 def order @order end |
#original ⇒ When::Events::Event
deep copy 時の元イベント
1679 1680 1681 |
# File 'lib/when_exe/events.rb', line 1679 def original @original end |
#rdf ⇒ Hash<String(prefix:name)=>Object>
RDF変数
1656 1657 1658 |
# File 'lib/when_exe/events.rb', line 1656 def rdf @rdf end |
#role ⇒ Hash<String(prefix:name)=>Object>
ロール変数
1648 1649 1650 |
# File 'lib/when_exe/events.rb', line 1648 def role @role end |
Instance Method Details
#abstract(item = ABSTRACT, method = :role) ⇒ String
Note:
ブロックを渡された場合、そのブロックに{}部分のマークアップを依頼する
指定の情報を{}部分のマークアップ処理など行って整形して返す
1711 1712 1713 1714 1715 1716 |
# File 'lib/when_exe/events.rb', line 1711 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
イベントの複製
1801 1802 1803 1804 1805 1806 1807 1808 |
# File 'lib/when_exe/events.rb', line 1801 def deep_copy result = self.dup result.csv = @csv.dup result.rdf = @rdf.dup result.role = @role.dup result.original = self result end |
#each_word ⇒ Object
HAS_PART対象の文字列中の{}で囲まれた語に対して yield で指定された処理を行う
1693 1694 1695 1696 1697 1698 1699 |
# File 'lib/when_exe/events.rb', line 1693 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
1741 1742 1743 |
# File 'lib/when_exe/events.rb', line 1741 def group @role[GROUP] end |
#source(item = SOURCE, method = :role) ⇒ Array<String(IRI), String(説明)>
指定の情報のIRIとその説明を返す
1726 1727 1728 1729 1730 1731 1732 1733 1734 |
# File 'lib/when_exe/events.rb', line 1726 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 を返す
1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 |
# File 'lib/when_exe/events.rb', line 1750 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 VALID if object.kind_of?(Range) object = object.original elsif object.respond_to?(:to_uri) object = object.to_uri end @statements << ::RDF::Statement(subject, @dataset.resource[predicate], object) # 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 |