# Facilitate a generic document that, when valid, will guarantee a level
# of content/search indices in the eXist applications.
# New content is set in the pmx namescape, to signify that it is an
# addition to the typical PoliticalMashup data.

namespace pm = "http://www.politicalmashup.nl"
namespace pmx = "http://www.politicalmashup.nl/extra"

# Include meta to redefine Meta with optional elements.
# Mimics document start from pmstructure.rnc by overriding meta start.
# By meta.rnc, toolbox.rnc is also included.
include "include/meta.rnc" {
  start = element root { external "include/docinfoX.rnc"?, MetaOptional, Content }
}

# Allow named entity information to pm:link
LinkContent &= attribute pmx:linktype {text}?
             & attribute pmx:entity-name {text}?
             & attribute pmx:entity-type {text}?
             & attribute pmx:entity-occurence {text}?
             & attribute pmx:entity-confidence {text}?

# Allow pmx:clouds in dc:subject
DcSubjectPmxContent &= element pmx:clouds { foreign-nodes }?
                    &  element pmx:source-content { foreign-nodes }?

# Meta definition with most fields optional, for simple documents.
MetaOptional =
    element meta {
        Id? &

        # Required.
        DcIdentifier &

        # Suggested fields.
        DcDate? &
        DcSource? &

        # Purely optional fields.
        DcContributor? &
        DcCoverage? &
        DcCreator? &
        DcLanguage? &
        DcPublisher? &
        DcRights? &
        DcDescription? &
        DcRelation? &
        DcSubject? &
        DcTitle? &
        DcType? &
        DcFormat?
    }


Content = GenericDocument

GenericDocument = element pmx:document { GenericDocumentContent }

# Generic documents can either contain a pmx:title and one or more pmx:text,
# or some combination of text, pm:p and other nodes.
GenericDocumentContent = 
                   Id
                   & CommonAttributes
                   & (
                       (GenericTitle & GenericText+) |
                       (text | Paragraph | foreign-nodes)*
                     )

GenericTitle =
    element pmx:title {GenericTitleContent}

GenericText =
    element pmx:text {GenericTextContent}

GenericTitleContent =
        Id
        & CommonAttributes
        & Title?
        & Type?
        & text

# pmx:text can contain any combination of text and pm:p.
GenericTextContent =
        Id
        & CommonAttributes
        & Title?
        & Type?
        & (text | Paragraph)*