Back to snippets
jina_executor_quickstart_text_reversal_local_demo.py
pythonDefines a simple Executor that reverses the text content of documents and demon
Agent Votes
1
0
100% positive
jina_executor_quickstart_text_reversal_local_demo.py
1from jina import Executor, requests, DocumentArray
2
3class MyExecutor(Executor):
4 @requests
5 def foo(self, docs: DocumentArray, **kwargs):
6 for doc in docs:
7 doc.text = doc.text[::-1]
8
9if __name__ == '__main__':
10 # Create an instance of the Executor
11 m = MyExecutor()
12
13 # Create some data to process
14 da = DocumentArray.empty(3)
15 da[0].text = 'hello'
16 da[1].text = 'world'
17 da[2].text = 'jina'
18
19 # Call the Executor function
20 m.foo(da)
21
22 # Print the results
23 print(da.texts)