<commit_before>jsoniq version "1.0";

(:
 : Copyright 2012-2015 28msec Inc.
 :)

(:~
 : <p>This module provides functionality for exporting archives to the XBRL format.</p>
 :
 : @author <NAME>
 : @author <NAME>
 :)
module namespace xbrl-export = "http://28.io/modules/xbrl/export";


import module namespace archives = "http://28.io/modules/xbrl/archives";
import module namespace concepts = "http://28.io/modules/xbrl/concepts";
import module namespace components = "http://28.io/modules/xbrl/components";
import module namespace networks = "http://28.io/modules/xbrl/networks";
import module namespace labels = "http://28.io/modules/xbrl/labels";

import module namespace archive = "http://zorba.io/modules/archive";
import module namespace credentials = "http://www.28msec.com/modules/credentials";
import schema namespace mongos = "http://www.28msec.com/modules/mongodb/types";

declare variable $xbrl-export:serialization-parameters :=
    <serialization-parameters xmlns="http://www.w3.org/2010/xslt-xquery-serialization">
      <method value="xml"/>
      <indent value="yes"/>
      <encoding value="UTF-8"/>
    </serialization-parameters>;

declare %private function xbrl-export:comment($options as object?) as comment()
{
  comment { "
    Generated: " || current-dateTime() || " (" || credentials:credentials("MongoDB", "xbrl").db || ")
    "||($options.Comment, "")[1]||"
    Generated by 28msec (CellStore/28.io)
  " }
};

declare function xbrl-export:schema(
    $archive as object,
    $options as object?)
as object
{
  {|
    let $taxonomyName as string := ($options.TaxonomyName, string($archive._id))[1]
    let $components as object* := components:components-for-archives($archive)
    let $concept-names as string* := distinct-values($components.Concepts[].Name[not $$ = $concepts:BUILT_IN_REPORT_ELEMENTS])
    let $prefixes as string* :=  distinct-values($concept-names ! (tokenize($$, ":")[1]))[not $$ = ("sec", "xbrl", "xbrl28", "fsa")]
    for $prefix as string in $prefixes
    let $namespace as string := ($archive.Namespaces.$prefix, "http://28.io/unknown" || $prefix)[1]
    return { $prefix: [
      xbrl-export:comment($options),
      <schema targetNamespace="{$namespace}"
          elementFormDefault="qualified"
          xmlns="http://www.w3.org/2001/XMLSchema"
          xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:link="http://www.xbrl.org/2003/linkbase"
          xmlns:xbrli="http://www.xbrl.org/2003/instance"
          xmlns:xbrldt="http://xbrl.org/2005/xbrldt"
          xmlns:nonnum="http://www.xbrl.org/dtr/type/non-numeric">
      {
          for $ns in keys($archive.Namespaces)
          return namespace { $ns } { $archive.Namespaces.$ns },
          for $p as string in $prefixes
          let $n as string := ($archive.Namespaces.$p, "http://28.io/unknown" || $p)[1]
          return <import namespace="{$n}" schemaLocation="{$taxonomyName}-{$p}.xsd"/>,
          <import namespace="http://www.xbrl.org/2003/instance" schemaLocation="http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd"/>,
          <import namespace="http://xbrl.org/2005/xbrldt" schemaLocation="http://www.xbrl.org/2005/xbrldt-2005.xsd" />,
          <import namespace="http://www.xbrl.org/dtr/type/non-numeric" schemaLocation="http://www.xbrl.org/dtr/type/nonNumeric-2009-12-16.xsd" />,
          components:to-xbrl-annotation($components, $taxonomyName),
          for $concept as element() in concepts:to-xbrl($components.Concepts[])
          group by $name := $concept/@name
          return $concept[1]
      }
      </schema>
    ] }
  |}
};

declare function xbrl-export:labels(
    $archive as object,
    $options as object?)
as node()*
{
  let $taxonomyName as string := ($options.TaxonomyName, string($archive._id))[1]
  let $components as object* := components:components-for-archives($archive)
  return (<commit_msg>:bug: Fix multiple prefixes.<commit_after>jsoniq version "1.0";

(:
 : Copyright 2012-2015 28msec Inc.
 :)

(:~
 : <p>This module provides functionality for exporting archives to the XBRL format.</p>
 :
 : @author <NAME>
 : @author <NAME>
 :)
module namespace xbrl-export = "http://28.io/modules/xbrl/export";


import module namespace archives = "http://28.io/modules/xbrl/archives";
import module namespace concepts = "http://28.io/modules/xbrl/concepts";
import module namespace components = "http://28.io/modules/xbrl/components";
import module namespace networks = "http://28.io/modules/xbrl/networks";
import module namespace labels = "http://28.io/modules/xbrl/labels";

import module namespace archive = "http://zorba.io/modules/archive";
import module namespace credentials = "http://www.28msec.com/modules/credentials";
import schema namespace mongos = "http://www.28msec.com/modules/mongodb/types";

declare variable $xbrl-export:serialization-parameters :=
    <serialization-parameters xmlns="http://www.w3.org/2010/xslt-xquery-serialization">
      <method value="xml"/>
      <indent value="yes"/>
      <encoding value="UTF-8"/>
    </serialization-parameters>;

declare %private function xbrl-export:comment($options as object?) as comment()
{
  comment { "
    Generated: " || current-dateTime() || " (" || credentials:credentials("MongoDB", "xbrl").db || ")
    "||($options.Comment, "")[1]||"
    Generated by 28msec (CellStore/28.io)
  " }
};

declare function xbrl-export:schema(
    $archive as object,
    $options as object?)
as object
{
  {|
    let $taxonomyName as string := ($options.TaxonomyName, string($archive._id))[1]
    let $components as object* := components:components-for-archives($archive)
    let $concept-names as string* := distinct-values($components.Concepts[].Name[not $$ = $concepts:BUILT_IN_REPORT_ELEMENTS])
    let $prefixes as string* :=  distinct-values($concept-names ! (tokenize($$, ":")[1]))[not $$ = ("sec", "xbrl", "xbrl28", "fsa")]
    for $prefix as string in $prefixes
    let $namespace as string := ($archive.Namespaces.$prefix, "http://28.io/unknown" || $prefix)[1]
    return { $prefix: [
      xbrl-export:comment($options),
      <schema targetNamespace="{$namespace}"
          elementFormDefault="qualified"
          xmlns="http://www.w3.org/2001/XMLSchema"
          xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:link="http://www.xbrl.org/2003/linkbase"
          xmlns:xbrli="http://www.xbrl.org/2003/instance"
          xmlns:xbrldt="http://xbrl.org/2005/xbrldt"
          xmlns:nonnum="http://www.xbrl.org/dtr/type/non-numeric">
      {
          for $ns in keys($archive.Namespaces)
          return namespace { $ns } { $archive.Namespaces.$ns },
          for $p as string in $prefixes
          where $p ne $prefix
          let $n as string := ($archive.Namespaces.$p, "http://28.io/unknown" || $p)[1]
          return <import namespace="{$n}" schemaLocation="{$taxonomyName}-{$p}.xsd"/>,
          <import namespace="http://www.xbrl.org/2003/instance" schemaLocation="http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd"/>,
          <import namespace="http://xbrl.org/2005/xbrldt" schemaLocation="http://www.xbrl.org/2005/xbrldt-2005.xsd" />,
          <import namespace="http://www.xbrl.org/dtr/type/non-numeric" schemaLocation="http://www.xbrl.org/dtr/type/nonNumeric-2009-12-16.xsd" />,
          components:to-xbrl-annotation($components, $taxonomyName),
          for $concept as element() in concepts:to-xbrl($components.Concepts[])
          group by $name := $concept/@name
          return $concept[1]
      }
      </schema>
    ] }
  |}
};

declare function xbrl-export:labels(
    $archive as object,
    $options as object?)
as node()*
{
  let $taxonomyName as string := ($options.TaxonomyName, string($archive._id))[1]
  let $components as object* := components:components-for-archives($archive)
  return (
{'fraction_non_alphanumeric': 0.17276814386640976, 'fraction_numerical': 0.028002569043031472, 'mean_word_length': 3.5346534653465347, 'pattern_counts': {'":': 2, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 26, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '360500', 'n_tokens_mistral': 2716, 'n_tokens_neox': 2528, 'n_words': 473}