########### used for https://solidos.github.io/solid-ui/docs/form-examples/structures2.html #####
######## THIS IS PART OF THE PRODUCTION PROFILE FORM ###########

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix owl: <http://www.w3.org/2002/07/owl#>.
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
@prefix ui: <http://www.w3.org/ns/ui#>.
@prefix schema: <http://schema.org/>.
@prefix vcard: <http://www.w3.org/2006/vcard/ns#>.

@prefix org: <http://www.w3.org/ns/org#>.
@prefix esco: <http://data.europa.eu/esco/model#>.
@prefix wd: <http://www.wikidata.org/entity/>.
@prefix wdt: <http://www.wikidata.org/prop/direct/>.

@prefix : <#>.

:this
    <http://purl.org/dc/elements/1.1/title> "Profile form" ;
    a ui:Form ;
    ui:parts (
      :OrganizationCreationForm
      ).

############ Organizations #################

:OrganizationCreationForm a ui:Form; 
  schema:name "Form for editing an organization using public data" ;
  ui:parts ( :OrgClassifier :OrgSwitch :OrganizationNameField :homePageURIField  ) .


  :OrgClassifier a ui:Classifier; ui:label "What sort of organization?"@en;
    ui:category solid:InterestingOrganization .

  # Ontology data to drive the classifier

  solid:InterestingOrganization owl:disjointUnionOf  (
   schema:Corporation
   schema:EducationalOrganization
   schema:ResearchOrganization  # Proposed. https://github.com/schemaorg/schemaorg/issues/2877
   schema:GovernmentOrganization
   schema:NGO
   schema:PerformingGroup # a band
   schema:Project # like Solid
   schema:SportsOrganization # a Team
   solid:OtherOrganization
  ) .

  # This until the schema.org ontology adopts it
  schema:ResearchOrganization a rdfs:Class; 
    rdfs:label "Research Organization"@en, "Organization de Recherche"@fr ,
     "organización de investigación"@es, "منظمة البحث"@ar, "अनुसंधान संगठन"@hi, "Forschungsorganisation"@de, "shirika la utafiti"@sw .

  :OrganizationNameField
      a ui:SingleLineTextField ;
      ui:label "Organization Name";
      ui:maxLength "200" ;
      ui:property schema:name ;
      ui:size    80 .

   :homePageURIField a ui:NamedNodeURIField; ui:size 80;
      ui:label "Home page URI"@en;
      ui:property  schema:uri . # @@ ??

#  Depending on the type of org, chose a different form

 :OrgSwitch a ui:Options; ui:dependingOn rdf:type;
   ui:case
   [ ui:for schema:Corporation; ui:use :CorporationForm ],
   [ ui:for schema:GovernmentOrganization; ui:use :GovernmentOrganizationForm ],
   [ ui:for schema:PerformingGroup; ui:use :PerformingGroupForm ],
   [ ui:for schema:Project; ui:use :ProjectForm ],
   [ ui:for schema:NGO; ui:use :NGOForm ],
   [ ui:for schema:EducationalOrganization; ui:use :EducationalOrganizationForm ],
   [ ui:for schema:ResearchOrganization; ui:use :ResearchOrganizationForm ],
   [ ui:for :SportsOrganization; ui:use :SportsOrganizationForm ],
   [ ui:for solid:OtherOrganization; ui:use :OtherOrganizationForm ].


  :CorporationForm a ui:Group; ui:weight 0; ui:parts ( :CorporationPrompt :CorporationAutocomplete ) .

      :CorporationPrompt a ui:Comment; ui:contents "Which corporation?".

      :CorporationAutocomplete a ui:AutocompleteField;
      a ui:AutocompleteField; ui:label "Corporation in wikidata";
           ui:size 60;
           ui:targetClass  <http://www.wikidata.org/entity/Q6881511>; # Enterprise
           ui:property solid:publicId; ui:dataSource :WikidataInstancesByName.

      :WikidataInstancesByName a ui:DataSource ;
        schema:name "Wikidata instances by name";
        ui:endpoint "https://query.wikidata.org/sparql" ;
        ui:searchByNameQuery """SELECT ?subject ?name
        WHERE {
          ?klass wdt:P279* $(targetClass) .
          ?subject wdt:P31 ?klass .
          ?subject rdfs:label ?name.
          FILTER regex(?name, "$(name)", "i")
        } LIMIT $(limit) """ ;

        # Note this form of the query is very experimental
        ui:searchByName [   ui:construct { ?subject schema:name ?name } ;
                            ui:where { ?klass wdt:P279 ?targetClass .
                                       ?subject wdt:P31 ?klass; rdfs:label ?name .
                                     };
                        ].

  :GovernmentOrganizationForm a ui:Group; ui:weight 0; ui:parts ( :GovernmentOrganizationPrompt :GovernmentOrganizationAutocomplete ) .

      :GovernmentOrganizationPrompt a ui:Comment; ui:contents "Which GovernmentOrganization?".

      :GovernmentOrganizationAutocomplete
      a ui:AutocompleteField; ui:label "GovernmentOrganization in wikidata";
           ui:size 60;
           ui:targetClass  <http://www.wikidata.org/entity/Q327333>; # GovernmentOrganization
           ui:property solid:publicId; ui:dataSource :WikidataInstancesByName.

    :EducationalOrganizationForm a ui:Group; ui:weight 1; ui:parts ( :EducationalOrganizationPrompt :EducationalOrganizationAutocomplete ) .

        :EducationalOrganizationPrompt a ui:Comment; ui:contents "Which Educational Organization?".

        :EducationalOrganizationAutocomplete
        a ui:AutocompleteField; ui:label "Educational Organization in wikidata";
             ui:size 60;
             ui:targetClass  <http://www.wikidata.org/entity/Q2385804>; # EducationalOrganization
             ui:property solid:publicId; ui:dataSource :WikidataInstancesByName.


    :ResearchOrganizationForm a ui:Group; ui:weight 0; ui:parts ( :ResearchOrganizationPrompt :ResearchOrganizationAutocomplete ) .

        :ResearchOrganizationPrompt a ui:Comment; ui:contents "Which Research Organization?".

        :ResearchOrganizationAutocomplete
        a ui:AutocompleteField; ui:label "Research Insitute in wikidata";
             ui:size 60;
             ui:targetClass  <http://www.wikidata.org/entity/Q31855>; # research institute
             ui:property solid:publicId; ui:dataSource :WikidataInstancesByName.


  :NGOForm a ui:Group; ui:weight 0; ui:parts ( :NGOPrompt :NGOAutocomplete ) .

      :NGOPrompt a ui:Comment; ui:contents "Which NGO?".

      :NGOAutocomplete
      a ui:AutocompleteField; ui:label "NGO in wikidata";
           ui:size 60;
           ui:targetClass  <http://www.wikidata.org/entity/Q163740>; # Non-profit org
           ui:property solid:publicId; ui:dataSource :WikidataInstancesByName.

  :PerformingGroupForm a ui:Group; ui:weight 0; ui:parts ( :PerformingGroupPrompt :PerformingGroupAutocomplete ) .

      :PerformingGroupPrompt a ui:Comment; ui:contents "Which PerformingGroup?".

      :PerformingGroupAutocomplete
      a ui:AutocompleteField; ui:label "PerformingGroup in wikidata";
           ui:size 60;
           ui:targetClass  <http://www.wikidata.org/entity/Q32178211>; # Music Org
           ui:property solid:publicId; ui:dataSource :WikidataInstancesByName.


  :ProjectForm a ui:Group; ui:weight 0; ui:parts ( :ProjectPrompt :ProjectAutocomplete ) . #  :ProjectAutocomplete - no: supress, as not in WD

      :ProjectPrompt a ui:Comment; ui:contents "Which Project?".

      :ProjectAutocomplete
      a ui:AutocompleteField; ui:label "Project in wikidata";
           ui:size 60;
           ui:targetClass  <http://www.wikidata.org/entity/Q170584>; # Project
           ui:property solid:publicId; ui:dataSource :WikidataInstancesByName.

  :SportsOrganizationForm a ui:Group; ui:weight 0; ui:parts ( :SportsOrganizationPrompt :SportsOrganizationAutocomplete ) .

      :SportsOrganizationPrompt a ui:Comment; ui:contents "Which Sports Organization?".

      :SportsOrganizationAutocomplete
      a ui:AutocompleteField; ui:label "SportsOrganization in wikidata";
           ui:size 60;
           ui:targetClass  <http://www.wikidata.org/entity/Q4438121>; # SportsOrganization
           ui:property solid:publicId; ui:dataSource :WikidataInstancesByName.

   :OtherOrganizationForm a ui:Group; ui:weight 0; ui:parts ( :OrganizationNameField :homePageURIField ) .


# ENDS