我正在尝试使用谷歌云翻译。我认为问题在于谷歌云翻译使用 UTF8,而 jvm 使用 UTF16。所以我在翻译中遇到了一些错字。例如 :
public static void main(String... args) throws Exception {
// Instantiates a client
Translate translate = TranslateOptions.getDefaultInstance().getService();
// The text to translate
String text = "Bonjour, à qui dois-je répondre? Non, C'est l'inverse...";
// Translates some text into Russian
Translation translation =
translate.translate(
text,
TranslateOption.sourceLanguage("fr"),
TranslateOption.targetLanguage("en"));
System.out.printf("Text: %s%n", text);
System.out.printf("Translation: %s%n", StringEscapeUtils.unescapeHtml(translation.getTranslatedText()));
}
Run Code Online (Sandbox Code Playgroud)
将返回 :
“翻译:你好,我该回答谁?不,相反……”
代替 :
翻译:你好,我应该回答谁?不,恰恰相反……
我们无法更改 java 字符串的编码,并且 Google Cloud Api 不会接受任何内容(字节 []?),但字符串。
有人知道如何解决吗?
感谢您阅读
编辑:此代码现在正在运行,我添加了来自 commons.apache 依赖项的 StringEscapeUtils.unescapeHtml。我不知道是否有其他方法可以做到。
I am running a Spark job. I have 4 cores and worker memory set to 5G. Application master is on another machine in the same network, and does not host any workers. This is my code:
private void myClass() {
// configuration of the spark context
SparkConf conf = new SparkConf().setAppName("myWork").setMaster("spark://myHostIp:7077").set("spark.driver.allowMultipleContexts", "true");
// creation of the spark context in wich we will run the algorithm
JavaSparkContext sc = new JavaSparkContext(conf);
// algorithm
for(int i = 0; i<200; i++) {
System.out.println("==============================================================="); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下代码访问Cloud Firestore:
void _submit(BuildContext context) async {
final DocumentReference postRef = Firestore.instance.document(dbPath);
Firestore.instance.runTransaction((transaction) async {
DocumentSnapshot freshSnap = await transaction.get(postRef);
await transaction.update(freshSnap.reference, {
'value': freshSnap['value'] + 1
});
});
}
Run Code Online (Sandbox Code Playgroud)
如果开启wifi或移动数据,一切正常。(如预期)
如果wifi和移动数据已关闭,则无法使用。(如预期)。但是当我等到超时(调用该方法之后),然后才打开移动数据和wifi时,它不再起作用,并且出现以下错误:
E/flutter ( 7041): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 7041): PlatformException(Error performing transaction, Timed out waiting for Task, null)
E/flutter ( 7041): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:547:7)
E/flutter ( 7041): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:279:18)
E/flutter ( 7041): <asynchronous suspension>
E/flutter ( 7041): #2 Firestore.runTransaction (file:///C:/{myPath}/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.7.3/lib/src/firestore.dart:115:10)
E/flutter ( 7041): …Run Code Online (Sandbox Code Playgroud) 我试图在我自己的数据上使用那里的代码:https ://www.tensorflow.org/tutorials/generative/cyclegan 。
在本教程中,使用以下代码创建 Dataset 对象:
dataset, metadata = tfds.load('cycle_gan/horse2zebra',
with_info=True, as_supervised=True)
train_horses, train_zebras = dataset['trainA'], dataset['trainB']
test_horses, test_zebras = dataset['testA'], dataset['testB']
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何从我自己的数据创建类似的对象,这些数据位于如下文件夹中:
data/trainA
data/trainB
data/testA
data/testB
Run Code Online (Sandbox Code Playgroud)
是否有一种类似于 flow_from_directory 方法的方法,以便以与 tfds.load(...) 相同的格式加载我的数据
看起来像的东西
train_horses = foo("data/trainA")
Run Code Online (Sandbox Code Playgroud) java ×2
apache-spark ×1
cpu-usage ×1
dart ×1
encoding ×1
firebase ×1
flutter ×1
generative-adversarial-network ×1
tensorflow ×1