# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 # Using Hatana-independent tmcl validator version #unless Object.const_defined?("Gem") && rtmgem = Gem.loaded_specs["rtm-tmcl"] # hatana_path = File.expand_path(File.join(File.dirname(__FILE__), "../../../rtm-hatana/lib")) # $LOAD_PATH.unshift hatana_path if File.directory?(hatana_path) #end #require 'rtm/hatana' Dir[File.join(File.dirname(__FILE__), 'tmcl/javalibs/*.jar')].each {|file| require file } module RTM module TopicMap # Validates this topic map against a schema. # # @param [TopicMap] schema The topic map used as schema to validate against # @return [Hash] The validation results as Hash: # Keys: :topic, :name, :occurrence, :association and :role. # Values: Hashes: keys are tmapi.core-objects and values validation results. def validate(schema) raise("schema must be a topic map") unless schema.is_a?(RTM::TopicMap) validator = Java::DeTopicmapslabTmclvalidator::TMCLValidator.new(schema, true) #true: use identifier for messages, false: use best_name for messages validation_results = validator.validate(self) #result is a HashMap result = {} %w[topic name occurrence association role other].each do |string| result[string.to_sym] = {} end # output it ... validation_results.each do |construct, validation_result| # key is a Construct # value is a Set of Validation Results case construct when Topic result[:topic][construct] = validation_result when Name result[:name][construct] = validation_result when Occurrence result[:occurrence][construct] = validation_result when Association result[:association][construct] = validation_result when Role result[:role][construct] = validation_result else result[:other][construct] = validation_result end end return result # result is a Hash end end end