# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../../spec_helper' module RTM::Sugar::Topic::Characteristics describe self do before(:each) do @tm = get_used_tm_sys_tm end after(:each) do @tm.close end describe "#internal_occurrences" do before(:each) do @uni_leipzig = @tm.get!("Uni_LE") @occ1 = @uni_leipzig.create_occurrence("Alter","600") @occ2 = @uni_leipzig.create_occurrence("Heimat","Sachsen") @occ3 = @uni_leipzig.create_occurrence("Webseite",@tm.create_locator("http://www.example.org/uni-leipzig")) end it "should give back all occurrences that are not of Datatype AnyURI" do @uni_leipzig.internal_occurrences.size.should == 2 @uni_leipzig.internal_occurrences.should include(@occ1) @uni_leipzig.internal_occurrences.should include(@occ2) end end #of describe "#internal_occurrences" do describe "#external_occurrences" do before(:each) do @uni_leipzig = @tm.get!("Uni_LE") @occ1 = @uni_leipzig.create_occurrence("Alter","600") @occ2 = @uni_leipzig.create_occurrence("Heimat","Sachsen") @occ3 = @uni_leipzig.create_occurrence("Webseite",@tm.create_locator("http://www.example.org/uni-leipzig")) end it "should give back all occurrences that are of Datatype AnyURI" do @uni_leipzig.external_occurrences.size.should == 1 @uni_leipzig.external_occurrences.should include(@occ3) end end #of describe "#external_occurrences" describe "#names_by" do before(:each) do @topic = @tm.get!("Hans") @name1 = @topic.create_name("first_name","Hans-Peter") @name2 = @topic.create_name("last_name","Mueller") @name3 = @topic.create_name("Hans",["mum"]) @name4 = @topic.create_name("full_name","Hans-Peter Mueller",["official"]) @name5 = @topic.create_name("Hansi",["endearment","mum"]) end it "should give back all names if no argument is given" do @topic.should have(5).names_by @topic.names_by.should include @name1, @name2, @name3, @name4, @name5 end it "should give back all names if all values in the argument hash equal :any" do @topic.names_by(:type => :any, :value => :any, :scope => :any).size.should == 5 @topic.names_by(:type => :any, :value => :any, :scope => :any).should include @name1, @name2, @name3, @name4, @name5 end it "should give back some names if a type is given (identifier is a String)" do @topic.names_by(:type => "first_name").size.should == 1 @topic.names_by(:type => "first_name").should include @name1 @topic.names_by(:type => ["first_name"]).should == @topic.names_by(:type => "first_name") end it "should give back some names if a type is given (identifier == :default)" do @topic.names_by(:type => :default).size.should == 2 @topic.names_by(:type => :default).should include @name3, @name5 @topic.names_by(:type => [:default]).should == @topic.names_by(:type => :default) end it "should give back some names if a type is given (identifier is a Locator)" do locator = @tm.create_locator("full_name") locator.should be_a_kind_of RTM::Locator @topic.names_by(:type => locator).size.should == 1 @topic.names_by(:type => locator).should include @name4 @topic.names_by(:type => [locator]).should == @topic.names_by(:type => locator) end it "should give back some names if a type is given (identifier is a Topic)" do topic = @tm.get("last_name") topic.should be_a_kind_of RTM::Topic @topic.names_by(:type => topic).size.should == 1 @topic.names_by(:type => topic).should include @name2 @topic.names_by(:type => [topic]).should == @topic.names_by(:type => topic) end it "should give back some names if several types are given (identifier is an Array)" do string = "first_name" locator = @tm.create_locator("full_name") topic = @tm.get("last_name") symbol = :default @topic.names_by(:type => [string,symbol,locator,topic]).size.should == 5 @topic.names_by(:type => [string,symbol,locator,topic]).should include @name1, @name2, @name3, @name4, @name5 end it "should give back no names if a type is given but not a type of a name" do @tm.get!("existing_dummy") @topic.names_by(:type => "dummy").should be_empty @topic.names_by(:type => "existing_dummy").should be_empty @topic.names_by(:type => @tm.create_locator("dummy")).should be_empty @topic.names_by(:type => @tm.create_locator("existing_dummy")).should be_empty @topic.names_by(:type => @tm.get("dummy")).should be_empty @topic.names_by(:type => @tm.get("existing_dummy")).should be_empty end it "should give back some names if several types are given but some are not types of names" do @topic.names_by(:type => ["dummy",:default,"first_name"]).size.should == 3 @topic.names_by(:type => ["dummy",:default,"first_name"]).should include @name1, @name3, @name5 end it "should not give back a name several times if several equals types are given" do @topic.names_by(:type => ["first_name","first_name"]).should == @topic.names_by(:type => "first_name") end it "should give back some names if a value is given" do @topic.names_by(:value => "Hansi").size.should == 1 @topic.names_by(:value => "Hansi").should include @name5 @topic.names_by(:value => ["Hansi"]).should == @topic.names_by(:value => "Hansi") end it "should give back some names if several values are given" do @topic.names_by(:value => ["Mueller","Hans-Peter"]).size.should == 2 @topic.names_by(:value => ["Mueller","Hans-Peter"]).should include @name1, @name2 end it "should give back no names if a value is given which is not a value of a name" do @topic.names_by(:value => "dummy").should be_empty end it "should give back some names if values are given but if not all are values of names" do @topic.names_by(:value => ["Hans","dummy"]).size.should == 1 @topic.names_by(:value => ["Hans","dummy"]).should include @name3 end it "should not give back a name several times if several equal values are given" do @topic.names_by(:value => ["Hans","Hans"]).should == @topic.names_by(:value => "Hans") end it "should give back no names if a value is given which is not a String" do @topic.names_by(:value => 1).should be_empty @topic.names_by(:value => [1]).should be_empty end it "should give back some names if a scope is given (one theme, String)" do @topic.names_by(:scope => "mum").size.should == 2 @topic.names_by(:scope => "mum").should include @name3, @name5 end it "should give back some names if a scope is given (one theme, Locator)" do locator = @tm.create_locator("official") @topic.names_by(:scope => locator).size.should == 1 @topic.names_by(:scope => locator).should include @name4 end it "should give back some names if a scope is given (one theme, Topic)" do topic = @tm.get("endearment") @topic.names_by(:scope => topic).size.should == 1 @topic.names_by(:scope => topic).should include @name5 end it "should give back some names if a scope is given (several themes)" do string = "mum" locator = @tm.create_locator("official") topic = @tm.get("endearment") @topic.names_by(:scope => [string,locator,topic]).size.should == 3 @topic.names_by(:scope => [string,locator,topic]).should include @name3, @name4, @name5 end it "should give back no names if a scope is given which is not a scope of a name" do @topic.names_by(:scope => "dummy").should be_empty end it "should give back some names if a scope is given (several themes) but if not all are in the scope of names" do @topic.names_by(:scope => ["mum","dummy"]).size.should == 2 @topic.names_by(:scope => ["mum","dummy"]).should include @name3, @name5 end it "should give back no names if a scope is given which is not a String, Locator or Topic" do lambda{topic.names_by(:scope => 1)}.should raise_error lambda{@topic.names_by(:scope => [1])}.should raise_error end it "should give back some names if scope is set to :ucs" do @topic.names_by(:scope => :ucs).size.should == 2 @topic.names_by(:scope => :ucs).should include(@name1, @name2) end it "should give back some names (in the unconstrained scope) if scope is []" do @topic.names_by(:scope => []).size.should == 2 @topic.names_by(:scope => []).should include(@name1, @name2) end it "should not give back a name several times if several equal themes are given" do @topic.names_by(:scope => ["official","official"]).should == @topic.names_by(:scope => "official") end it "should give back name in the unconstrained scope if scope equals :ucs" it "should not create Topics" do @tm.get("dummy1").should be_nil @tm.get("dummy2").should be_nil @tm.get("dummy3").should be_nil @topic.names_by(:type => "dummy1", :value => "dummy2", :scope => "dummy3").should be_empty @tm.get("dummy1").should be_nil @tm.get("dummy2").should be_nil @tm.get("dummy3").should be_nil end end describe "#occurrences_by" do before(:each) do @topic = @tm.get!("Hans") @occ1 = @topic.create_occurrence("birthyear","1980") @occ2 = @topic.create_occurrence("favourite_colour","blue") @occ3 = @topic.create_occurrence("age","29",:scope => ["2009"]) @occ4 = @topic.create_occurrence("hair_colour","blue",:scope => ["2009","halloween"]) @occ5 = @topic.create_occurrence("age","20",:datatype => RTM::PSI[:Integer],:scope => ["2000"]) end it "should give back all occurrences if no argument is given" do @topic.should have(5).occurrences_by @topic.occurrences_by.should include @occ1, @occ2, @occ3, @occ4, @occ5 end it "should give back all occurrences if all values in the argument hash equal :any" do @topic.occurrences_by(:type => :any, :value => :any, :scope => :any, :datatype => :any).size.should == 5 @topic.occurrences_by(:type => :any, :value => :any, :scope => :any, :datatype => :any).should include @occ1, @occ2, @occ3, @occ4, @occ5 end it "should give back some occurrences if a type is given (identifier is a String)" do @topic.occurrences_by(:type => "birthyear").size.should == 1 @topic.occurrences_by(:type => "birthyear").should include @occ1 end it "should give back some occurrences if a type is given (identifier is a Locator)" do locator = @tm.create_locator("age") locator.should be_a_kind_of RTM::Locator @topic.occurrences_by(:type => locator).size.should == 2 @topic.occurrences_by(:type => locator).should include @occ3, @occ5 end it "should give back some occurrences if a type is given (identifier is a Topic)" do topic = @tm.get("hair_colour") topic.should be_a_kind_of RTM::Topic @topic.occurrences_by(:type => topic).size.should == 1 @topic.occurrences_by(:type => topic).should include @occ4 end it "should give back some occurrences if several types are given (identifier is an Array)" do string = "birthyear" locator = @tm.create_locator("age") topic = @tm.get("hair_colour") @topic.occurrences_by(:type => [string,locator,topic]).size.should == 4 @topic.occurrences_by(:type => [string,locator,topic]).should include @occ1, @occ3, @occ4, @occ5 end it "should give back no occurrences if a type is given which is not a type of an occurrence" do @tm.get!("existing_dummy") @topic.occurrences_by(:type => "dummy").should be_empty @topic.occurrences_by(:type => "existing_dummy").should be_empty @topic.occurrences_by(:type => @tm.create_locator("dummy")).should be_empty @topic.occurrences_by(:type => @tm.create_locator("existing_dummy")).should be_empty @topic.occurrences_by(:type => @tm.get("dummy")).should be_empty @topic.occurrences_by(:type => @tm.get("existing_dummy")).should be_empty end it "should give back some occurrences if several types are given but some are not types of occurrences" do @topic.occurrences_by(:type => ["dummy","age"]).size.should == 2 @topic.occurrences_by(:type => ["dummy","age"]).should include @occ3, @occ5 end it "should not give back an occurrence several times if several equal types are given" do @topic.occurrences_by(:type => ["birthyear","birthyear"]).should == @topic.occurrences_by(:type => "birthyear") end it "should give back some occurrences if a value is given" do @topic.occurrences_by(:value => "1980").size.should == 1 @topic.occurrences_by(:value => "1980").should include @occ1 @topic.occurrences_by(:value => "29").size.should == 1 @topic.occurrences_by(:value => "29").should include @occ3 end it "should give back some occurrences if several values are given" do @topic.occurrences_by(:value => ["blue","20"]).size.should == 3 @topic.occurrences_by(:value => ["blue","20"]).should include @occ2, @occ4, @occ5 end it "should give back no occurrences if a value is given which is not a value of an occurrence" do @topic.occurrences_by(:value => "dummy").should be_empty end it "should give back some occurrences if several values are given but some are not values of occurrences" do @topic.occurrences_by(:value => ["blue","dummy","29"]).size.should == 3 @topic.occurrences_by(:value => ["blue","dummy","29"]).should include @occ2, @occ3, @occ4 end it "should not give back an occurrence several times if several equal values are given" do @topic.occurrences_by(:value => ["20","20"]).should == @topic.occurrences_by(:value => "20") end it "should give back no names if a value is given which is not a String" do @topic.occurrences_by(:value => 20).should be_empty @topic.occurrences_by(:value => [20]).should be_empty end it "should give back some occurrences if a scope is given (one theme, String)" do @topic.occurrences_by(:scope => "2009").size.should == 2 @topic.occurrences_by(:scope => "2009").should include @occ3, @occ4 end it "should give back some occurrences if a scope is given (one theme, Locator)" do locator = @tm.create_locator("2000") @topic.occurrences_by(:scope => locator).size.should == 1 @topic.occurrences_by(:scope => locator).should include @occ5 end it "should give back some occurrences if a scope is given (one theme, Topic)" do topic = @tm.get("halloween") @topic.occurrences_by(:scope => topic).size.should == 1 @topic.occurrences_by(:scope => topic).should include @occ4 end it "should give back some occurrences if a scope is given (several themes)" do string = "2000" locator = @tm.create_locator("2009") topic = @tm.get("halloween") @topic.occurrences_by(:scope => [string,locator,topic]).size.should == 3 @topic.occurrences_by(:scope => [string,locator,topic]).should include @occ3, @occ4, @occ5 end it "should give back no occurrences if a scope is given which is not a scope of an occurrence" do @topic.occurrences_by(:scope => "dummy").should be_empty end it "should give back some occurrences if a scope is given (several themes) but if not all are in the scope of occurrences" do @topic.occurrences_by(:scope => ["2000","dummy"]).size.should == 1 @topic.occurrences_by(:scope => ["2000","dummy"]).should include @occ5 end it "should give back no occurrences if a scope is given which is not a String, Locator or Topic" do lambda{topic.occurrences_by(:scope => 1)}.should raise_error lambda{@topic.occurrences_by(:scope => [1])}.should raise_error end it "should not give back an occurrence several times if several equal themes are given" do @topic.occurrences_by(:scope => ["2009","2009"]).should == @topic.occurrences_by(:scope => "2009") end it "should give back some occurrences (in the unconstrained scope) if scope is set to :ucs" do @topic.occurrences_by(:scope => :ucs).size.should == 2 @topic.occurrences_by(:scope => :ucs).should include(@occ1, @occ2) end it "should give back some occurrences (in the unconstrained scope) if scope is []" do @topic.occurrences_by(:scope => []).size.should == 2 @topic.occurrences_by(:scope => []).should include(@occ1, @occ2) end it "should test datatype" it "should not create Topics" do @tm.get("dummy1").should be_nil @tm.get("dummy2").should be_nil @tm.get("dummy3").should be_nil @tm.get("dummy4").should be_nil @topic.occurrences_by(:type => "dummy1", :value => "dummy2", :datatype => "dummy3", :scope => "dummy4").should be_empty @tm.get("dummy1").should be_nil @tm.get("dummy2").should be_nil @tm.get("dummy3").should be_nil @tm.get("dummy4").should be_nil end end # describe "#characteristics_by" do # before(:each) do # # end # it "should be testend .." do # # end # end end # of describe self end # of module