Commit ee0b3965 authored by gijs's avatar gijs

Frontend for the annotator

parent a92b0fe3
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.<br>
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.<br>
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.<br>
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.<br>
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.<br>
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
### Analyzing the Bundle Size
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
### Making a Progressive Web App
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
### Advanced Configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
### Deployment
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
### `npm run build` fails to minify
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
npm install --save redux react-redux react-router-dom connected-react-router redux-thunk history redux-logger
......@@ -31,39 +31,85 @@
}
}
.sentenceClassList {
.sentence--classlist {
display: grid;
grid-template-columns: 25% 25% 25% 25%;
grid-auto-rows: 150px;
}
.sentenceClassList--class {
.sentence--classlist--class {
padding: 1em;
margin: .5em;
background: black;
color: white;
background: white;
color: block;
display: flex;
text-align: center;
align-items: center;
justify-content: space-around;
border: none;
border: 2px solid transparent;
border-radius: 5px 5px;
font-size: 120%;
}
.sentenceClassList--class:hover {
background: red;
.sentence--classlist--class:hover {
border: 2px solid black;
}
.sentenceClassList--class:active {
background: darkorange;
box-shadow: inset 0px 0px 5px rgba(0,0,0,.5);
.sentence--classlist--class:active {
border: 2px solid orange;
box-shadow: inset 0px 0px 2px rgba(0,0,0,.5);
}
.sentenceClassList--class[data-selected="true"] {
background: orange;
.sentence--classlist--class[data-selected="true"] {
border: 2px solid blue;
}
.sentence {
font-size: 200%;
font-size: 200%;
line-height: 1.75;
font-family: serif;
margin: 1em 3em;
padding: 1em 3em;
overflow-y: auto;
display: flex;
flex-direction: column;
justify-content: center;
}
.sentence--window {
color: rgb(75%,75%,75%);
}
#annotator {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: auto;
display: flex;
flex-direction: column;
}
.sentence--actions button {
margin: 0 1em;
font-size: 120%;
}
.sentence--actions {
flex: 0 0;
padding: 1em 0;
border-top: 1px solid black;
border-bottom: 1px solid black;
}
.sentence {
flex: 1;
}
.sentence--classlist {
flex: 0 0;
}
.interface--hint {
padding: 1em 0 0 0;
font-size: 120%;
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ export const sentenceLoad = () => (dispatch, _) => {
export const sentencePost = () => (dispatch, getState) => {
const state = getState().sentence;
dispatch({ type: SENTENCE_POST })
apiSentencePost(state.id, state.selectedClass)
apiSentencePost(state.sentence_id, state.selectedClass)
.then(() => {
dispatch({ type: SENTENCE_POST_SUCCESS });
dispatch(sentenceLoad())
......@@ -36,11 +36,11 @@ export const sentencePost = () => (dispatch, getState) => {
}
export const sentenceMarkDirty = () => (dispatch, getState) => {
const state = getState();
const state = getState().sentence;
dispatch({
type: SENTENCE_MARK_DIRTY
});
apiSentenceMarkDirty(state.id)
apiSentenceMarkDirty(state.sentence_id)
.then(() => {
dispatch({ type: SENTENCE_MARK_DIRTY_SUCCESS });
dispatch(sentenceLoad())
......@@ -53,8 +53,8 @@ export const sentenceClassSelect = (selectedClass) => ({
selectedClass: selectedClass
})
export const sentenceLoadSuccess = ({ id, sentence, predictions }) => ({
export const sentenceLoadSuccess = ({ sentence_id, sentence, before, after }) => ({
type: SENTENCE_LOAD_SUCCESS,
id, sentence, predictions })
sentence_id, sentence, before, after })
export const sentenceLoadFail = () => ({ type: SENTENCE_LOAD_FAIL })
\ No newline at end of file
......@@ -3,7 +3,7 @@ import Sentence from './Sentence';
import SentenceActions from './SentenceActions';
import SentenceClassList from './SentenceClassList';
import { t } from '../utils'
export const Annotator = class extends Component {
componentDidMount = () => {
......@@ -16,6 +16,8 @@ export const Annotator = class extends Component {
classesLoading,
message,
sentence,
before,
after,
sentenceClasses,
sentenceLoading,
selectedClass,
......@@ -27,13 +29,14 @@ export const Annotator = class extends Component {
return <section id="annotator">
<section id="application-message">{ message }</section>
<Sentence sentence={ sentence } before={ before } after={ after }/>
<SentenceActions
sentenceLoading={ sentenceLoading }
sentenceClassSelected={ selectedClass }
sentenceLoad={ sentenceLoad }
sentencePost={ sentencePost }
sentenceMarkDirty={ sentenceMarkDirty } />
<Sentence sentence={ sentence } />
<section className="interface--hint">{ t('select_class_explanation') }</section>
<SentenceClassList
classesLoading={ classesLoading }
sentenceClasses={ sentenceClasses }
......
import React from 'react';
export const Sentence = ({
sentence
sentence,
before,
after
}) => (
<section className="sentence">
{ before.map(sentence => <p className="sentence--window">{ sentence }</p>) }
<p>{ sentence }</p>
{ after.map(sentence => <p className="sentence--window">{ sentence }</p>) }
</section>
);
......
......@@ -9,10 +9,10 @@ export const SentenceActions = ({
sentencePost,
sentenceMarkDirty
}) => (
<section id="sentenceActions">
<section class="sentence--actions">
<button onClick={ sentenceMarkDirty } disabled={ sentenceLoading }>{ t('mark_dirty_button') }</button>
<button onClick={ sentenceLoad } disabled={ sentenceLoading }>{ t('sentence_load_new_button') }</button>
{ (sentenceClassSelected) ? <button onClick={ sentencePost } disabled={ sentenceLoading }>{ t('sentence_submit_button') }</button> : '' }
{ (sentenceClassSelected !== null) ? <button onClick={ sentencePost } disabled={ sentenceLoading }>{ t('sentence_submit_button') }</button> : '' }
</section>
)
......
......@@ -5,9 +5,9 @@ export const SentenceClassList = ({
sentenceClassSelected,
sentenceClassSelect
}) => (
<section className="sentenceClassList">
<section className="sentence--classlist">
{ sentenceClasses.map((sentenceClass, k) => (
<button className="sentenceClassList--class" onClick={ () => sentenceClassSelect(k) } data-selected={ (k === sentenceClassSelected) }>
<button className="sentence--classlist--class" onClick={ () => sentenceClassSelect(k) } data-selected={ (k === sentenceClassSelected) }>
{ sentenceClass}
</button>
))}
......
......@@ -12,6 +12,7 @@ export const messages = {
'sentence_post': 'Sending annotation',
'sentence_post_fail': 'Unable to send annotation',
'sentence_post_success': 'Sent annotation to the server',
'select_class_explanation': 'Select a class for this sentence'
}
export default messages;
\ No newline at end of file
......@@ -7,9 +7,10 @@ import {
import { extractUpdate, extractProps } from '../utils';
const initialState = {
id: null,
sentence_id: null,
sentence: '',
predictions: [],
before: [],
after: [],
selectedClass: null
}
......@@ -20,7 +21,7 @@ export default function sentence (state = initialState, action) {
case SENTENCE_LOAD_SUCCESS:
return {
...state,
...extractProps(action, ['id', 'sentence', 'predictions']),
...extractProps(action, ['sentence_id', 'sentence', 'before', 'after']),
selectedClass: initialState.selectedClass
}
default:
......
......@@ -71,11 +71,11 @@ const post = (url, data) => {
export const sentenceGet = () => get('sentence')
export const sentencePost = (id, sentenceClass) => post('classify', { id, sentenceClass })
export const sentencePost = (sentence_id, classification) => post('classify', { sentence_id, classification })
export const classesGet = () => get('classes')
export const sentenceMarkDirty = (id) => post('mark_dirty', { id })
export const sentenceMarkDirty = (sentence_id) => post('mark_dirty', { sentence_id })
// export const replaceToken = (token, pos) => post('token/replace', { token, pos })
......
flask
gunicorn
\ No newline at end of file
gunicorn
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment