# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../spec_helper' module RTM::Majortom::Sugar::Topic describe self do before(:each) do @tm = get_used_tm_sys_tm @tm.clear end after(:each) do @tm.close end describe "#best_label with special examples" do it "should give back an identifier if the name is empty" do topic = @tm.get!("Leipzig") topic.create_name("") topic.best_label.should == "http://www.topicmapslab.de/Leipzig" end it "should give back the shorter value" do topic = @tm.get!("Leipzig") topic.create_name("Le ipzig in Sachsen", ["long"]) topic.create_name("Short", ["short"]) topic.best_label.should == "Short" end it "should give back the shorter value" do topic = @tm.get!("Leipzig") topic.create_name("Le ipzig in Sachsen", ["long", "theme"]) topic.create_name("Short", ["short", "theme"]) topic.best_label("theme").should == "Short" end it "should handle Berlin in the totTM" do @tm.clear @tm.from_xtm(File.join(File.dirname(__FILE__), "/../../../rtm/spec/resources/toyTM.xtm")) berlin = @tm.get("http://en.wikipedia.org/wiki/Berlin") berlin.should_not be_nil berlin.best_label.should == "Berlin" end describe "should handle topic with only a" do it "item identifier" do t = @tm.get!("ii:an_item_identifier") t.best_label.should == "http://www.topicmapslab.de/an_item_identifier" t.best_label("theme").should == "http://www.topicmapslab.de/an_item_identifier" @tm.get!("theme") t.best_label("theme").should == "http://www.topicmapslab.de/an_item_identifier" end it "subject identifier" do t = @tm.get!("si:a_subject_identifier") t.best_label.should == "http://www.topicmapslab.de/a_subject_identifier" t.best_label("theme").should == "http://www.topicmapslab.de/a_subject_identifier" @tm.get!("theme") t.best_label("theme").should == "http://www.topicmapslab.de/a_subject_identifier" end it "subject locator" do t = @tm.get!("sl:a_subject_locator") t.best_label.should == "http://www.topicmapslab.de/a_subject_locator" t.best_label("theme").should == "http://www.topicmapslab.de/a_subject_locator" @tm.get!("theme") t.best_label("theme").should == "http://www.topicmapslab.de/a_subject_locator" end end describe "should handle the toyTM including michael jackson" do it "should give back the best_label of all topics" do @tm.clear @tm.from_xtm(File.join(File.dirname(__FILE__), "/../../../rtm/spec/resources/toyTM_MJ.xtm")) creator = @tm.get!("http://en.wikipedia.org/wiki/Creator") lit = @tm.get!("http://en.wikipedia.org/wiki/Lithuania") creator.best_label(lit).should == "Creator" # @tm.topics.each do |t| # puts "++++++++++" # t.best_label # @tm.topics.each do |theme| # begin # t.best_label(theme) # rescue # puts t.reference # #puts t.names.first # puts theme.reference # # end # end # end end end end describe "#best_label" do before(:each) do @topic = @tm.get!("Leipzig") @topic.add_si("LE") @topic.add_ii("http://example.org/id-10") @topic.add_ii("1") end after(:each) do @topic.best_label.should be_a_kind_of String end it "should return an identfier if the topic has no name, resolved" do @topic.best_label.should == "http://www.topicmapslab.de/LE" end it "should give back the name if the topic has one name" do @topic["-city-name"] = "Leipzig" @topic.best_label.should == "Leipzig" end it "should give back the default name if the topic has several names" do @topic["-city-name"] = "Leipzig" @topic["-"] = "Leipzisch" @topic.best_label.should == "Leipzisch" end it "should give back the default name with the smallest value if the topic has several names" do @topic["-city-name"] = "Leipzig" @topic["-"] = "LE" @topic["-"] = "Leipzisch" @topic["-"] = "A Schone Stadt" @topic.best_label.should == "LE" end it "should give back the default name with the smallest value sorted alphabetically if the topic has several names" do @topic["-city-name"] = "Leipzig" @topic["-"] = "LE" @topic["-"] = "Leipzisch" @topic["-"] = "LA" @topic.best_label.should == "LA" end it "should give back the name with the given theme" do @topic["-city-name name @test_theme"] = "Leipzig" @topic["-"] = "LE" @topic["-"] = "Leipzisch" @topic["-"] = "LA" test_theme = @tm.get("test_theme") test_theme.should_not be_nil @topic.best_label(test_theme).should == "Leipzig" end it "should give back the name with the given theme preferring default names" do @topic["-city-name name @test_theme"] = "Leipzig" @topic["-"] = "LE" @topic["- @test_theme"] = "Leipzisch" @topic["- @test_theme_other"] = "LA" test_theme = @tm.get("test_theme") test_theme.should_not be_nil @topic.best_label(test_theme).should == "Leipzisch" end end end end