Skip to content

Commit

Permalink
Rename Boolean LitType to BooleanLitType.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 464623452
  • Loading branch information
cjqian authored and LIT team committed Aug 1, 2022
1 parent ef72bfc commit 40d14e5
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 20 deletions.
10 changes: 9 additions & 1 deletion lit_nlp/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ class SequenceSalience(Salience):


@attr.s(auto_attribs=True, frozen=True, kw_only=True)
class Boolean(LitType):
class BooleanLitType(LitType):
"""Boolean value."""
default: bool = False

Expand Down Expand Up @@ -517,3 +517,11 @@ class InfluentialExamples(LitType):


# LINT.ThenChange(../client/lib/lit_types.ts)

# Type aliases for backend use.
# `Boolean` and `String` are existing datatypes in TypeScript, so `Boolean` and
# `String` LitTypes are serialized and instantiated as `BooleanLitType` and
# `StringLitType`, respectively, to avoid collisions with language features on
# the front-end.
Boolean = BooleanLitType
String = StringLitType
4 changes: 2 additions & 2 deletions lit_nlp/client/elements/interpreter_controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {customElement, property} from 'lit/decorators';
import {observable} from 'mobx';

import {ReactiveElement} from '../lib/elements';
import {CategoryLabel, FieldMatcher, LitType, LitTypeWithVocab, MultiFieldMatcher, Scalar, SparseMultilabel} from '../lib/lit_types';
import {BooleanLitType, CategoryLabel, FieldMatcher, LitType, LitTypeWithVocab, MultiFieldMatcher, Scalar, SparseMultilabel} from '../lib/lit_types';
import {styles as sharedStyles} from '../lib/shared_styles.css';
import {Spec} from '../lib/types';
import {isLitSubtype} from '../lib/utils';
Expand Down Expand Up @@ -203,7 +203,7 @@ export class InterpreterControls extends ReactiveElement {
</div>
`;
// clang-format on
} else if (isLitSubtype(controlType, ['Boolean'])) {
} else if (controlType instanceof BooleanLitType) {
// Render a checkbox.
const toggleVal = () => {
const val = !!this.settings[name];
Expand Down
2 changes: 1 addition & 1 deletion lit_nlp/client/lib/lit_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ export class SequenceSalience extends Salience {
* A boolean value.
*/
@registered
export class Boolean extends LitType {
export class BooleanLitType extends LitType {
override default : boolean = false;
}

Expand Down
2 changes: 1 addition & 1 deletion lit_nlp/client/lib/testing_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const mockMetadata: LitMetadata = {
'sex': createLitType('CategoryLabel', {'vocab': ['female', 'male']}),
'species': createLitType(
'CategoryLabel', {'vocab': ['Adelie', 'Chinstrap', 'Gentoo']}),
'isAlive': createLitType('Boolean', {'required': false})
'isAlive': createLitType('BooleanLitType', {'required': false})
}
}
},
Expand Down
7 changes: 3 additions & 4 deletions lit_nlp/client/modules/data_table_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import {computed, observable} from 'mobx';
import {app} from '../core/app';
import {LitModule} from '../core/lit_module';
import {ColumnHeader, DataTable, TableData} from '../elements/table';
import {LitType, LitTypeWithVocab} from '../lib/lit_types';
import {BooleanLitType, LitType, LitTypeWithVocab} from '../lib/lit_types';
import {styles as sharedStyles} from '../lib/shared_styles.css';
import {formatForDisplay, IndexedInput, ModelInfoMap, Spec} from '../lib/types';
import {compareArrays, isLitSubtype} from '../lib/utils';
import {compareArrays} from '../lib/utils';
import {DataService, FocusService, SelectionService} from '../services/services';

import {styles} from './data_table_module.css';
Expand Down Expand Up @@ -80,8 +80,7 @@ export class DataTableModule extends LitModule {
get keys(): ColumnHeader[] {
const createColumnHeader = (name: string, type: LitType) => {
const header = {name, vocab: (type as LitTypeWithVocab).vocab};
// TODO(b/162269499): Rename Boolean to BooleanLitType.
if (isLitSubtype(type, 'Boolean')) {
if (type instanceof BooleanLitType) {
header.vocab = ['✔', ' '];
}
return header;
Expand Down
13 changes: 6 additions & 7 deletions lit_nlp/client/modules/datapoint_editor_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ import {customElement} from 'lit/decorators';
import {classMap} from 'lit/directives/class-map';
import {styleMap} from 'lit/directives/style-map';
import {computed, observable, when} from 'mobx';

import {app} from '../core/app';
import {LitModule} from '../core/lit_module';
import {ListLitType, LitTypeWithVocab, SparseMultilabel, StringLitType} from '../lib/lit_types';
import {BooleanLitType, EdgeLabels, ImageBytes, ListLitType, LitTypeWithVocab, MultiSegmentAnnotations, SpanLabels, SparseMultilabel, StringLitType} from '../lib/lit_types';
import {styles as sharedStyles} from '../lib/shared_styles.css';
import {AnnotationCluster, defaultValueByField, EdgeLabel, formatAnnotationCluster, formatEdgeLabel, formatSpanLabel, IndexedInput, Input, ModelInfoMap, SCROLL_SYNC_CSS_CLASS, SpanLabel, Spec} from '../lib/types';
import {findSpecKeys, isLitSubtype} from '../lib/utils';
Expand Down Expand Up @@ -552,15 +551,15 @@ export class DatapointEditorModule extends LitModule {
renderInput = renderTokensInput;
entryContentClasses['entry-content-long'] = true;
entryContentClasses['left-align'] = true;
} else if (isLitSubtype(fieldSpec, 'SpanLabels')) {
} else if (fieldSpec instanceof SpanLabels) {
renderInput = renderSpanLabelsNonEditable;
} else if (isLitSubtype(fieldSpec, 'EdgeLabels')) {
} else if (fieldSpec instanceof EdgeLabels) {
renderInput = renderEdgeLabelsNonEditable;
} else if (isLitSubtype(fieldSpec, 'MultiSegmentAnnotations')) {
} else if (fieldSpec instanceof MultiSegmentAnnotations) {
renderInput = renderMultiSegmentAnnotationsNonEditable;
} else if (isLitSubtype(fieldSpec, 'ImageBytes')) {
} else if (fieldSpec instanceof ImageBytes) {
renderInput = renderImage;
} else if (isLitSubtype(fieldSpec, 'Boolean')) {
} else if (fieldSpec instanceof BooleanLitType) {
renderInput = renderBoolean;
} else {
entryContentClasses['entry-content-long'] = true;
Expand Down
5 changes: 3 additions & 2 deletions lit_nlp/client/services/data_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ export class DataService extends LitService {
source);
if (predSpec.parent != null) {
this.addColumnFromList(
correctness, data, key, correctnessName, createLitType('Boolean'),
source, () => null, BINARY_NEG_POS);
correctness, data, key, correctnessName,
createLitType('BooleanLitType'), source, () => null,
BINARY_NEG_POS);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lit_nlp/client/services/group_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ export class GroupService extends LitService {
@computed
get booleanFeatureNames(): string[] {
const dataSpec = this.appState.currentDatasetSpec;
const names = findSpecKeys(dataSpec, 'Boolean');
return names.concat(this.dataService.getColNamesOfType('Boolean'));
const names = findSpecKeys(dataSpec, 'BooleanLitType');
return names.concat(this.dataService.getColNamesOfType('BooleanLitType'));
}

/** Get the names of all dense features (boolean, categorical, and numeric) */
Expand Down

0 comments on commit 40d14e5

Please sign in to comment.