<commit_before>/*
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Copyright 2020 Google LLC.
 *
 * This code may only be used under the BSD style license found at
 * http://polymer.github.io/LICENSE.txt
 *
 * Code distributed by Google as part of this project is also subject to an additional IP rights
 * grant found at
 * http://polymer.github.io/PATENTS.txt
 */

package com.google.android.`as`.oss.policies.api

import com.google.android.`as`.oss.policies.api.annotation.Annotation
import com.google.android.`as`.oss.policies.api.capabilities.Capabilities
import com.google.android.`as`.oss.policies.api.capabilities.Capability
import com.google.android.`as`.oss.policies.api.contextrules.AllowAllContextsRule
import com.google.android.`as`.oss.policies.api.contextrules.PolicyContextRule

/** The name of a field within an entity. */
typealias FieldName = String

/** Defines a data usage policy. See [PolicyProto] for the canonical definition of a policy. */
// TODO: Serialize allowedContext in Chronicle ledger
data class Policy(
  val name: String,
  val egressType: String,
  val description: String = "",
  val targets: List<PolicyTarget> = emptyList(),
  val configs: Map<String, PolicyConfig> = emptyMap(),
  val annotations: List<Annotation> = emptyList(),
  val allowedContext: PolicyContextRule = AllowAllContextsRule
) {
  /** All fields mentioned the policy (includes nested fields). */
  val allFields: List<PolicyField> = collectAllFields()

  /** The set of all redaction labels mentioned in the policy. */
  val allRedactionLabels: Set<String> = allFields.flatMap { it.redactedUsages.keys }.toSet()<commit_msg>Internal change<commit_after>/*
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Copyright 2020 Google LLC.
 *
 * This code may only be used under the BSD style license found at
 * http://polymer.github.io/LICENSE.txt
 *
 * Code distributed by Google as part of this project is also subject to an additional IP rights
 * grant found at
 * http://polymer.github.io/PATENTS.txt
 */

package com.google.android.`as`.oss.policies.api

import com.google.android.`as`.oss.policies.api.annotation.Annotation
import com.google.android.`as`.oss.policies.api.capabilities.Capabilities
import com.google.android.`as`.oss.policies.api.capabilities.Capability
import com.google.android.`as`.oss.policies.api.contextrules.AllowAllContextsRule
import com.google.android.`as`.oss.policies.api.contextrules.PolicyContextRule

/** The name of a field within an entity. */
typealias FieldName = String

/** Defines a data usage policy. See [PolicyProto] for the canonical definition of a policy. */
data class Policy(
  val name: String,
  val egressType: String,
  val description: String = "",
  val targets: List<PolicyTarget> = emptyList(),
  val configs: Map<String, PolicyConfig> = emptyMap(),
  val annotations: List<Annotation> = emptyList(),
  val allowedContext: PolicyContextRule = AllowAllContextsRule
) {
  /** All fields mentioned the policy (includes nested fields). */
  val allFields: List<PolicyField> = collectAllFields()

  /** The set of all redaction labels mentioned in the policy. */
  val allRedactionLabels: Set<String> = allFields.flatMap { it.redactedUsages.keys }.toSet()
{'fraction_non_alphanumeric': 0.09944367176634214, 'fraction_numerical': 0.005563282336578581, 'mean_word_length': 4.2303030303030305, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '7584802', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1185, 'n_words': 438}