
module RDF
    module Photo
        class Document
            XML_MATCH = %q(<?xml version=['"]1\.0["'])

            attr_reader :multiple, :ns, :iCount
            attr_reader :aRdf_comments, :text
                   
            begin 
                require 'rubygems'
                require_gem 'rubyrdf'
            rescue LoadError=>e
            end
            
            require 'basicrdf'
            
            require 'tempfile'
            
            def initialize aComment

                @aRdf_comments = Array.new
                @iCount = 0
                @text = []
                aComment.each{ |mComment|
                    sComment = mComment.text
                    @text << sComment 
                    # TODO: now, we only match XML comments and
                    # not "RDF" 
                    if sComment =~ /#{XML_MATCH}/
                        rdf_tempfile = Tempfile.new("rdf_file")
                        rdf_tempfile.puts(sComment)
                        rdf_tempfile.close
                        rdf_tempfile_name = rdf_tempfile.path.gsub(/\\/,'/')
                        
                        gRdf = Loader.get_rdf rdf_tempfile_name
              
                        @aRdf_comments << gRdf
                        @iCount+= 1
                        
                    end
                }
                
                # build the ns hash
                @ns = Hash.new
                @aRdf_comments.each{ |rdf_graph|
                    rdf_graph.statements.each{ |rdf_statement|
                        data = rdf_statement.predicate.to_s.split(/#/)
                        ns = data[0] + "#"
                        property = data[1]
                        @ns[ns] ||= Array.new
                        @ns[ns] << rdf_statement
                    }
                }
            end
            def Document.new_from_file
                raise "NotImplemented"
            end
            def Document.new_from_jfif_image jImage
                return Document.new(jImage.comments)
            end
        end

        class Property
        end
    end
end
