1.2.5 • Published 3 years ago

@ia2coop/ia2-annotation-tool v1.2.5

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
3 years ago

IA² | Annotation tool


About

The ia2-annotation-tool is a react library that provides the a annotation feature for the IA² project. This library wraps up the API calls to the IA² server.

Pre-requisites

  • Node 12.18.2

Install library in your application

npm install https://github.com/instituciones-abiertas/ia2-annotation-tool.git

Components

Editor

PropDescriptionTypeExample
styleEditor css stylesObject{ backgroundColor: 'var(--contrast-color)', lineHeight: 2, fontSize: 'large', padding: '3em' }
annotationsInitial text annotationsArray[{ id: 1, start: 18, end: 28, tag: 'PERSON', should_anonymized: true, human_marked_ocurrency: false }]
tagsAnnotation tags/entitiesArray[{ id: 1, name: 'PERSON', description: 'Una persona', should_anonimyzation: true, enable_multiple_selection: false }]
textDocument TextString'On Monday night, Mr. Fallon will have a co-host for the first time: The rapper Cardi B, who just released her first album, Invasion of Privacy'
onAnnotationsChangeFunction to acces the annotations stateFunction(deleteAnnotations, newAnnotations) => console.log(deleteAnnotations, newAnnotations)
multipleSelectionEnableBoolean that indicates if the MultipleEntitiesSelector component is enabledBooleanTrue
onMultipleSelectionFunction that make the integration with the API to execute getAllOcurrenciesOf action.FunctionLook an example into the description of the MultipleEntitiesSelector component.

Instructions

Instructions is a visual component, similar to a header, that is placed above the text annotator.

PropDescriptionTypeExample
titleThe instructions titleString'Select a label'
subtitleThe isntructions subtitleString'Then delete, add or change identified entities.
legendsReferences to the coloured entitiesArray[{color: '#00D6A1', description: 'Anonymized' }, { color: '#ffca00', description: 'Not anonymized' }]
childrenChildren nodes to be renderedArray<div><ul><li>I'm a child</li><li>I'm another child</li></ul></div>

MultipleEntitiesSelector

MultipleEntitiesSelector ia a visual a component that is redered into the Instruction component and allows to find all the ocurrencies of the curren selected annotations. It works by integrated it with the API action getAllOcurrenciesOf.

PropDescriptionTypeExample
onMultipleSelectionFunction that make the integration with the API to execute getAllOcurrenciesOf action.FunctionSee example below

Example of function to pass as onMultipleSelection prop:

const onMultipleSelection = (
  newAnnotations,
  deleteAnnotations,
  tagList,
) => async => {
  try {
    const docId = state.id
    const response = await api.getAllOcurrenciesOf(
      newAnnotations,
      docId,
      deleteAnnotations,
      entityList
    );
    const mappedResponse = {
      ...response,
      ents: response.ents.map((ent) => {
        return {
          ...ent,
          class: ent.should_anonymized ? styles.anonymousmark : styles.mark,
        };
      }),
    };
    console.log(mappedResponse)
  } catch (err) {
     console.log(err)
  }
};

Api

Props

PropDescriptionTypeExample
api_urlThe url for the API servicesString'http://localhost:8000'

Access functions to the IA² API

FunctionDescriptionParamsResponse
userLoginAuthenticates a user{"email": "demo@mydomain.coop", "password": "123456"}{"refresh": "token", "access": "token"}
userLogoutTerminates a user session
refreshTokenRenews a user session{"refresh": "token"}{"access": "token"}
getSubjectsReturns the available subjects[{"name_subject": "Penal", "last_update": "2020-10-06T11:45:03.328000-03:00"}]
getEntitiesReturns the available labeling entities[{"id": 29, "name": "PER", "description": "Una persona", "should_anonimyzation": false, "enable_multiple_selection": false}]
getDocAnalysisUploads a file and returns a list of detected entities{ "file": <A valid file as a multipart request>}{"text": "On Monday night, Mr. Fallon will have a co-host for the first time: The rapper Cardi B, who just released her first album, Invasion of Privacy", "ents": [{"id": 420, "start": 17, "end": 26, "tag": "PER", "should_anonymized": true, "human_marked_ocurrency": false}], "id": 1}
getAnonymizedDocTakes added and deleted annotations and returns new entities{"newOcurrencies": [{ "start": 27, "end": 33, "tag": "PER", "should_anonymized": true }], "deleteOcurrencies": [{ "start": 141, "end": 143, "tag": "MISC", "should_anonymized": true }]}{"anonymous_text": "On Monday night, Mr. Fallon will have a co-host for the first time: The rapper Cardi B, who just released her first album, Invasion of Privacy", "data_visualization": {"entitiesResult": [{"id": 29, "name": "PER", "description": "Una persona", "should_anonimyzation": false, "enable_multiple_selection": false}], "total": {"model_total_ent": 63, "model_wrong_ent": 1, "human_total_ent": 2, "percent_total": 95.38}}}
getDocToDownloadDownloads an anonymized document
getDocPublishedToDrivePublishes an anonymized document to Google Drive
getDocPublishedPublishes an anonymized document to Dropbox
selectSubjectTells the server what subject to use
getAllOcurrenciesOfFind all the ocurrencies of the current selected annotations{"newOcurrencies":[{start: 22, end: 28, text: "Fallon", should_anonymized: true, human_marked_ocurrency: true, tag: "PER"}],"deleteOcurrencies":[], "entityList":[4]}"text":"On Monday night, Mr. Fallon will have a co-host for the first time: The rapper Cardi B, who just released her first album, Invasion of Privacy. Fallon had got lot of audience that day.","ents":[{"id":10056,"start":22,"end":28,"tag":"PER","should_anonymized":true,"human_marked_ocurrency":true},{"id":10057,"start":145,"end":151,"tag":"PER","should_anonymized":true,"human_marked_ocurrency":true}],"id":390}
getHechoStatsReturn hecho stats{"start": "2000-01-20", "end": "2001-01-20"}{"otros": 2 , "total": 5 , "violencia": 3 , "violencia_genero": 3}
getEdadStatsReturn edad stats{"start": "2000-01-20", "end": "2001-01-20"}{"promedio_acusadx": 30 , "promedio_victima": 30}
getLugarStatsReturn lugar stats{"start": "2000-01-20", "end": "2001-01-20"}`{"nombre": "John Doe" , "cantidad": 30}, {"nombre": "Jane Doe", "cantidad": 30}`
checkStatusDownloadDocumentIndicates if the document is available for download`{"status":False }`

BarSeries

PropDescriptionTypeExample
titleGraphic titleString'Promedio de Edades'
seriesData Series to showArray of Objects {name: "String", value: "Number"})[{name: "Acusadxs", value:20}, { name: "Victima", value: 20 }]
orientationBars orientationoneOf("v","f")v = vertical, h: horizontal
colorsColor PaletteArray'["#FF0000", "#00FF00", "#0000FF"]'
textStyleTitle text stylesObjectEcharts TextStyle

PieSeries

PropDescriptionTypeExample
titleGraphic titleString'Cantidad de sentencias'
seriesData Series to showArray of Objects {name: "String", value: "Number"})[{name:"Violecia", value:10}, { name: "violencia genero", value: 20 }]
colorsColor PaletteArray'["#FF0000", "#00FF00", "#0000FF"]'
textStyleTitle text stylesObjectEcharts TextStyle
showLegendShow Pie legendBooltrue or false

Development

Installl

npm install

Build as library

npm run build

Run example

npm start

Contributing

Please, make sure to read our contribution guidelines before opening a pull request.

License

GNU General Public License version 3